Skip to content

Instantly share code, notes, and snippets.

@everdaniel
Created April 13, 2013 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everdaniel/5380164 to your computer and use it in GitHub Desktop.
Save everdaniel/5380164 to your computer and use it in GitHub Desktop.
Demo files from a Management Application for the Hospitality Industry
<?php
/**
* Dashboard Controller
*
**/
class Dashboard extends Controller
{
/**
* dashboard::dashboard()
* Class constructor
*
* @access public
* @param void
* @return void
*/
function Dashboard()
{
parent::Controller();
$this->template['section_class'] = 'table landing';
// Check if current user is logged in
$this->aa_auth->bouncer();
// Store user privileges in a local var (to use inside the controller)
$this->user_id = $this->session->userdata('user_id');
$this->user_acl = $this->aa_auth->refresh_auth(2);
$this->template['page_id'] = 'events';
// Sotre user privileges in a template var (to use inside views)
$this->template['user_acl'] = $this->user_acl;
$this->load->helper('url');
$prefs['template'] = $this->load->view('event/calendar_template', array(), TRUE);
$prefs['local_time'] = now();
$prefs['start_day'] = 'sunday';
$prefs['month_type'] = 'long';
$prefs['day_type'] = 'long';
$prefs['show_next_prev'] = TRUE;
$prefs['next_prev_url'] = site_url('event/dashboard/index');
$this->load->library('calendar', $prefs);
$this->load->library('pagination');
$this->load->library('layout');
$this->layout->set_layout('layout_main/index');
$this->load->helper('date');
$this->load->helper('text');
$this->load->model('user_model');
$this->load->model('event/event_model', 'event_model');
$this->load->model('system/venue_model', 'venue_model');
$this->load->model('misc_model', 'misc_model');
if (($this->user_acl['superadmin'] === FALSE) || ($this->user_acl['admin'] === FALSE))
{
// Is not a superadmin or admin, means it is a manager or user,
// lets see if they have access to this app
if ($this->user_model->has_application($this->user_id, 'events') === FALSE)
{
$this->session->set_flashdata('flashmessage', 'You don\'t have access enabled to the event application.');
redirect('users/dashboard');
}
}
$this->template['body_jscode'] = 'onload="javascript: hide_login();"';
$this->template['h1_title'] = 'Event Manager';
$this->template['jscode_domready'] = '';
// Load the enabled venues
if (($this->user_acl['superadmin'] === FALSE) || ($this->user_acl['admin'] === FALSE))
{
$this->enabled_venues = $this->venue_model->get_venues_ddlist($this->user_id);
}
else
{
$this->enabled_venues = $this->venue_model->get_venues_ddlist();
}
// Base Filter Conditions for the Calendar and List View
$this->filter_options['event.event_client_approved'] = 'yes';
$this->filter_options['event_version.client_approved'] = 'yes';
}
/**
* dashboard::index()
*
* @access public
* @param void
* @return void
* */
function index()
{
$css_files = array(
'assets/css/framework/forms.css',
'assets/css/sourced/smoothbox/smoothbox.css'
);
$this->template['css_files'] = asset_link($css_files, 'css');
$js_files = array(
'assets/js/sourced/tiny_mce/tiny_mce.js',
'assets/js/sourced/smoothbox/smoothbox.js',
'assets/js/framework/multiselect.fx.js',
'assets/js/extensions/email.contract.js',
'assets/js/framework/transitions.fx.js',
'assets/js/extensions/sortable.table.js',
'assets/js/framework/validation.fx.js'
);
$this->template['js_files'] = asset_link($js_files, 'js');
$this->template['jscode'] = '
var site_url = "' . site_url() . '";
var updated_content = false;
initHtmlEmailEditor();
';
$this->template['users'] = $this->event_model->get_users();
$this->template['jscode_domready'].= "\n//change_drop_down('dd_users', 'dd_users_label');\n";
$this->calendar_view();
$this->list_view();
$this->layout->view($this->template);
}
/**
* dashboard::calendar_view()
*
* @access public
* @param void
* @return void
* */
function calendar_view()
{
$filter_options = array();
$users = $this->template['users'];
$data['filtering_options'] = 'Now viewing %venues from %users for period %month %year.';
if (count($this->enabled_venues) > 1)
{
// enabled_venues holds the array suitable for use with dropdown, means, it has an
// extra element [NULL] = Please select bla bla, so, first, we extract all of the
// keys from that array and store it in venue_keys (it saves an additional empty item)
$venue_keys = array_keys($this->enabled_venues);
// Ok, now "we get" the first item into empty value, this way, we take out the first empty item
$empty = array_shift($venue_keys);
// now we have only real keys on venue_keys and we can send it to the model, which will turn the
// array into an where_in statement
$this->filter_options['event_version.event_venue'] = $venue_keys;
$data['filtering_options'] = str_replace('%venues', 'all venues', $data['filtering_options']);
}
else
$data['filtering_options'] = str_replace('%venues', 'all venues', $data['filtering_options']);
$data['filtering_options'] = str_replace('%users', 'all users', $data['filtering_options']);
if ($this->input->post('btn_calendar'))
{
$user = $this->input->post('fu_calendar', TRUE);
if (trim($user) != '')
{
$this->filter_options['event.event_prepared_by'] = $user;
$data['filtering_options'] = str_replace('%users', $users[$this->input->post('fu_calendar', TRUE)], $data['filtering_options']);
}
}
if ($this->input->post('fvcalendar'))
{
// The User wants to filter the events by Venue
$filter_venue = $this->input->post('fvcalendar');
$this->filter_options['event_version.event_venue'] = $filter_venue;
if (is_array($filter_venue))
{
$to_replace = '';
foreach ($filter_venue as $venue)
$to_replace.= trim($this->enabled_venues[$venue]) . ',';
$to_replace = substr($to_replace, 0, strlen($to_replace) - 1) . ' events';
}
else
$to_replace = $this->enabled_venues[$filter_venue] . ' events';
$data['filtering_options'] = str_replace('all venues', $to_replace, $data['filtering_options']);
}
// Calendar View
$year = $this->uri->segment(4) == FALSE ? date('Y') : $this->uri->segment(4);
$month = $this->uri->segment(5) == FALSE ? date('m') : $this->uri->segment(5);
$months = $this->misc_model->get_months();
$data['filtering_options'] = str_replace('%month', $months[$month], $data['filtering_options']);
$data['filtering_options'] = str_replace('%year', $year, $data['filtering_options']);
$this->filter_options['event_year'] = $year;
$this->filter_options['event_month'] = $month;
$calendar_data = $this->event_model->get_calendar_events($this->filter_options);
$data['current_calendar'] = $this->calendar->generate($this->filter_options['event_year'], $this->filter_options['event_month'], $calendar_data);
$this->template['lightbox_holder'] = '';
foreach ($calendar_data as $index => $value)
{
$lb_vars['day'] = $index;
$lb_vars['object_id'] = 'lb_' . $index;
$lb_vars['content'] = $value;
$this->template['lightbox_holder'].= $this->load->view('event/calendar/day', $lb_vars, TRUE);
}
$data['venues'] = $this->enabled_venues;
$data['users'] = $users;
$this->template['section_1_title'] = '';
$this->template['section_1'] = $this->load->view('event/dashboard/calendar', $data, TRUE);
}
/**
* dashboard::list_view()
*
* @access public
* @param void
* @return void
* */
function list_view()
{
$data['events'] = $this->event_model->get_all_events($this->filter_options, NULL, array('field' => 'event_date', 'type' => ''));
$total_rows = $this->event_model->get_total_records($this->filter_options);
$this->template['jscode_domready'].= "call_venue_multiselect();";
$data['venues'] = $this->enabled_venues;
$page = 'event/dashboard/list';
$this->template['section_2_title'] = '';
$this->template['section_2'] = $this->load->view($page, $data, TRUE);
}
/**
* dashboard::sort_contracts()
*
* @access public
* @param void
* @return void
* */
function sort_contracts()
{
$filter_options = array();
if (count($this->enabled_venues) > 1)
{
// enabled_venues holds the array suitable for use with dropdown, means, it has an
// extra element [NULL] = Please select bla bla, so, first, we extract all of the
// keys from that array and store it in venue_keys (it saves an additional empty item)
$venue_keys = array_keys($this->enabled_venues);
// Ok, now "we get" the first item into empty value, this way, we take out the first empty item
$empty = array_shift($venue_keys);
// now we have only real keys on venue_keys and we can send it to the model, which will turn the
// array into an where_in statement
$filter_options['event_version.event_venue'] = $venue_keys;
}
$css_files = 'assets/css/framework/forms.css';
$this->template['css_files'] = asset_link($css_files, 'css');
$js_files = array(
'assets/js/extensions/sortable.table.js',
'assets/js/framework/multiselect.fx.js',
'assets/js/framework/transitions.fx.js',
'assets/js/framework/validation.fx.js',
'assets/js/extensions/event.fx.js'
);
$this->template['js_files'] = asset_link($js_files, 'js');
$this->template['jscode_domready'].= "call_sort_contracts_form();\n";
$venues = $this->enabled_venues;
$venues[NULL] = 'All Venues';
$data['venues'] = $venues;
$data['users'] = $this->event_model->get_users(TRUE);
$data['periods'] = $this->event_model->get_event_periods();
$this->template['section_1_title'] = 'Events / Sort Contracts';
$this->template['section_1'] = $this->load->view('event/dashboard/sort', $data, TRUE);
$this->layout->view($this->template);
}
}
<?php
/**
* Event Model
*
**/
class Event_model extends Model
{
var $main_table = 'event';
/**
* Class constructor
* @access public
* @param void
* @return void
*/
function Event_model()
{
parent::Model();
}
/**
* Add a new record on $main_table
*
* @name add
* @access public
* @param array $data
* @return array
*/
function add($data)
{
$result = $this->db->insert($this->main_table, $data);
return array('status' => $result, 'insert_id' => $this->db->insert_id());
}
/**
* Add a file record
*
* @name add_file
* @access public
* @param array $data
* @return array
*/
function add_file($data)
{
$result = $this->db->insert('event_file', $data);
return array('status' => $result, 'insert_id' => $this->db->insert_id());
}
/**
* Add a comment
*
* @name add_comment
* @access public
* @param array $data
* @return array
*/
function add_comment($data)
{
$result = $this->db->insert('event_comment', $data);
return array('status' => $result, 'insert_id' => $this->db->insert_id());
}
/**
* Edits a record on $main_table based on $where conditions
*
* @name edit
* @access public
* @param array $data
* @param array $where
* @return array
*/
function edit($data, $where)
{
if ($where != NULL)
{
if (is_array($where) === TRUE)
{
foreach ($where as $index => $value)
{
$this->db->where($index, $value);
}
}
else
$this->db->where($where);
}
$result = $this->db->update($this->main_table, $data);
return array('status' => $result, 'affected_rows' => $this->db->affected_rows());
}
/**
* Deletes a record(s) on $main_table based on $where conditions
*
* @name delete
* @access public
* @param array $data
* @param array $where
* @return array
*/
function delete($where)
{
if ($where != NULL)
{
if (is_array($where) === TRUE)
{
foreach ($where as $index => $value)
{
$this->db->where($index, $value);
}
}
else
$this->db->where($where);
}
$result = $this->db->delete($this->main_table);
return array('status' => $result, 'affected_rows' => $this->db->affected_rows());
}
/**
* Returns data based on $filter conditions
*
* @name get_record
* @access public
* @param array $filter
* @return object
*/
function get_record($filter = NULL)
{
$this->db->select('*');
$this->db->from($this->main_table);
if ($filter != NULL)
{
if (is_array($filter) === TRUE)
{
foreach ($filter as $index => $value)
{
$this->db->where($index, $value);
}
}
else
$this->db->where($filter);
}
$rs = $this->db->get();
return $rs->row();
}
/**
* Returns records based on $filter conditions limited by $limit
*
* @name get_records
* @access public
* @param array $filter
* @param array $filter
* @return object
*/
function get_records($filter = NULL, $limit = NULL)
{
$this->db->select('*');
$this->db->from($this->main_table);
if ($filter != NULL)
{
if (is_array($filter) === TRUE)
{
foreach ($filter as $index => $value)
{
$this->db->where($index, $value);
}
}
else
$this->db->where($filter);
}
if ($limit != NULL)
{
$this->db->limit($limit['limit'], $limit['offset']);
}
return $this->db->get();
}
/**
* Returns total records based on $filter conditions
*
* @name get_total_users
* @access public
* @param array $filter
* @return integer
*/
function get_total_records($filter = NULL)
{
if ($filter != NULL)
{
if (is_array($filter) === TRUE)
{
foreach ($filter as $index => $value)
{
if (is_array($value))
$this->db->where_in($index, $value);
else
if ($index == 'event_year')
$this->db->where("EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif ($index == 'event_month')
$this->db->where("EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif ($index == 'event_day')
$this->db->where("EXTRACT(day FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif (is_array($value))
$this->db->where_in($index, $value);
else
$this->db->where($index, $value);
}
}
else
{
$this->db->where($filter);
}
$this->db->join('event_version', 'event.event_id = event_version.event_id', 'right outer');
$this->db->where('event.event_client_approved', 'yes');
return $this->db->count_all_results($this->main_table);
}
else
{
$this->db->where('event.event_client_approved', 'yes');
return $this->db->count_all_results($this->main_table);
}
}
/**
* Get all of the client approved events
*
* @name get_all_events
* @access public
* @param array filter
* @param array limit
* @param array order_by
* @return object
*/
function get_all_events($filter = NULL, $limit = NULL, $order_by = NULL)
{
// Select Event Fields
$this->db->select('event_version.event_id, event_version.event_venue, event_version.event_name');
$this->db->select('event_version.event_date, event_version.event_people, event_version.event_details');
$this->db->select('event_version.event_version, event_version.event_total, event.event_deposit_taken');
$this->db->select('event.event_balance_owed, event_version.event_reservation');
// Select User Fields
$this->db->select('user.first_name, user.last_name, user.username, user.first_name, user.last_name');
// Select Venue Fields
$this->db->select('venue.venue_id, venue.venue_name');
$this->db->from($this->main_table);
$this->db->join('event_version', 'event_version.event_id = event.event_id', 'left');
$this->db->join('venue', 'event_version.event_venue = venue.venue_id', 'left');
$this->db->join('user', 'event.event_prepared_by = user.user_id', 'left');
$this->db->where('event_version.client_approved', 'yes');
if ($filter != NULL)
{
if (is_array($filter) === TRUE)
{
foreach ($filter as $index => $value)
{
if (is_array($value))
$this->db->where_in($index, $value);
else
if ($index == 'event_year')
$this->db->where("EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif ($index == 'event_month')
$this->db->where("EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif ($index == 'event_day')
$this->db->where("EXTRACT(day FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif (is_array($value))
$this->db->where_in($index, $value);
else
$this->db->where($index, $value);
}
}
else
$this->db->where($filter);
}
if ($limit != NULL)
{
$this->db->limit($limit['limit'], $limit['offset']);
}
if ($order_by != NULL)
{
$this->db->order_by($order_by['field'], $order_by['type']);
}
return $this->db->get();
}
/**
* Get Calendar Events (array suitable for use with Calendar Library)
*
* @name get_calendar_events
* @access public
* @param array filter
* @return array
*/
function get_calendar_events($filter = NULL)
{
$tmp = array();
$this->db->select('event_version.event_id, event_version.event_version, venue.venue_name, event_version.event_name');
$this->db->select('event_version.event_contact_name, event_version.event_contact_phone, event_version.event_contact_email');
$this->db->select('event_version.event_date, event_version.event_start_time, event_version.event_end_time');
$this->db->select('event_version.event_type, event_version.event_people, event_version.event_minimum_guarantee');
$this->db->select('event_version.event_remarks, event_version.event_details, event_version.event_reservation');
$select_array = array(
'EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS event_year',
'EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS event_month',
'EXTRACT(day FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS event_day'
);
$this->db->select($select_array);
$this->db->from('event');
$this->db->join('event_version', 'event.event_id = event_version.event_id', 'left');
$this->db->join('venue', 'event_version.event_venue = venue.venue_id', 'left');
$this->db->where('event_version.client_approved', 'yes');
if ($filter != NULL)
{
if (is_array($filter) === TRUE)
{
foreach ($filter as $index => $value)
{
if ($index == 'event_year')
$this->db->where("EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif ($index == 'event_month')
$this->db->where("EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif ($index == 'event_day')
$this->db->where("EXTRACT(day FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = " . $value, NULL, FALSE);
elseif (is_array($value))
$this->db->where_in($index, $value);
else
$this->db->where($index, $value);
}
}
else
$this->db->where($filter);
}
$this->db->order_by('event_version.event_date', 'asc');
$rs = $this->db->get();
if ($rs->num_rows() > 0)
{
$current_day = 0;
$day = 0;
$lines = '';
foreach ($rs->result() as $row)
{
// if we don't do this, we will have a number
// like 01 and this wont work with the calendar
// library
$day = $row->event_day * 1;
if (($current_day != $day) && (trim($lines) != ''))
$tmp[$current_day] = $this->load->view('event/calendar/day_lightbox', array('lines' => $lines), TRUE);
if ($current_day == $day)
$lines.= $this->load->view('event/calendar/day_lightbox_lines', array('row' => $row), TRUE);
else
$lines = $this->load->view('event/calendar/day_lightbox_lines', array('row' => $row), TRUE);
$current_day = $day;
}
$tmp[$current_day] = $this->load->view('event/calendar/day_lightbox', array('lines' => $lines), TRUE);
}
return $tmp;
}
/**
* Get Comments
*
* @name get_comments
* @access public
* @param array filter
* @param array limit
* @param array order_by
* @return object
*/
function get_comments($filter = NULL, $limit = NULL, $order_by = NULL)
{
// Select Event Comment Fields
$this->db->select('event_comment.comment_id, event_comment.event_id, event_comment.user_id, event_comment.comment_text, event_comment.comment_date');
// Select Event Fields
$this->db->select('event.event_title, event.event_date, event.event_people, event.event_details');
// Select User Fields
$this->db->select('user.username, user.first_name, user.middle_name, user.last_name, user.email');
$this->db->from('event_comment');
$this->db->join('event', 'event_comment.event_id = event.event_id', 'left');
$this->db->join('user', 'event_comment.user_id = user.user_id', 'left');
if ($filter != NULL)
{
if (is_array($filter) === TRUE)
{
foreach ($filter as $index => $value)
{
$this->db->where($index, $value);
}
}
else
$this->db->where($filter);
}
if ($limit != NULL)
{
$this->db->limit($limit['limit'], $limit['offset']);
}
if ($order_by != NULL)
{
$this->db->order_by($order_by['field'], $order_by['type']);
}
return $this->db->get();
}
/**
* Get Event Users
*
* @name get_event_users
* @access public
* @param void
* @return array
*/
function get_sorted_events($where)
{
$this->db->select('venue_name, username');
$this->db->select('EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS event_year', FALSE);
$this->db->select('EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS event_month', FALSE);
$this->db->select('SUM(event_total) AS grand_total', FALSE);
$this->db->from('event');
$this->db->join('event_version', 'event.event_id = event_version.event_id', 'left');
$this->db->join('venue', 'venue.venue_id = event_version.event_venue', 'left');
$this->db->join('user', 'user.user_id = event.event_prepared_by', 'left');
$this->db->where("event.event_client_approved", 'yes');
$this->db->where("event_version.client_approved", 'yes');
// filtering by venue
if (isset($where['filter_venue']))
{
$this->db->where('event_version.event_venue', $where['filter_venue']);
}
// filtering by user
if (isset($where['filter_user']))
{
$this->db->where('event.event_prepared_by', $where['filter_user']);
}
// filtering by period
if (isset($where['filter_period']))
{
$this->db->where('EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = ' . $where['filter_period']['year'], NULL, FALSE);
$this->db->where('EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = ' . $where['filter_period']['month'], NULL, FALSE);
}
$this->db->group_by('venue_name');
$this->db->group_by('username');
$this->db->group_by('event_year');
$this->db->group_by('event_month');
$this->db->order_by('venue_name');
$this->db->order_by('username');
$this->db->order_by('event_year');
$this->db->order_by('event_month');
return $this->db->get();
}
/**
* Get Event Users
*
* @name get_event_users
* @access public
* @param void
* @return array
*/
function get_event_users()
{
$tmp[NULL] = 'Please choose user...';
$this->db->select('DISTINCT event.event_prepared_by AS user_id, user.last_name, user.first_name', FALSE);
$this->db->from('event');
$this->db->join('user', 'event.event_prepared_by = user.user_id', 'left');
$this->db->order_by('user.last_name');
$this->db->order_by('user.first_name');
$rs = $this->db->get();
if ($rs->num_rows() > 0)
foreach ($rs->result() as $row)
$tmp[$row->user_id] = $row->last_name . ', ' . $row->first_name;
return $tmp;
}
/**
* Get Event Periods
*
* @name get_event_periods
* @access public
* @param void
* @return array
*/
function get_event_periods()
{
$tmp[NULL] = 'All periods';
$this->db->select('DISTINCT EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS month, EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) AS year', FALSE);
$this->db->from('event_version');
$this->db->where('event_version.client_approved', 'yes');
$this->db->order_by('EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time))', 'DESC');
$this->db->order_by('EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time))', 'DESC');
$rs = $this->db->get();
if ($rs->num_rows() > 0)
foreach ($rs->result() as $row)
$tmp[$row->month . '-' . $row->year] = $this->get_month($row->month) . '/' . $row->year;
return $tmp;
}
/**
* Get Month
*
* @name get_month
* @access public
* @param integer month
* @return string
*/
function get_month($month_number)
{
$tmp[1] = 'January';
$tmp[2] = 'February';
$tmp[3] = 'March';
$tmp[4] = 'April';
$tmp[5] = 'May';
$tmp[6] = 'June';
$tmp[7] = 'July';
$tmp[8] = 'August';
$tmp[9] = 'September';
$tmp[10] = 'October';
$tmp[11] = 'November';
$tmp[12] = 'December';
return isset($tmp[$month_number]) ? $tmp[$month_number] : '';
}
/**
* Get Users
*
* @name get_users
* @access public
* @param void
* @return array
*/
function get_users($short_name = FALSE)
{
$tmp = array(NULL => 'All users');
$this->db->select('user_id, username, first_name, last_name');
$this->db->from('user');
if ($short_name == TRUE)
{
$this->db->order_by('username');
}
else
{
$this->db->order_by('last_name');
$this->db->order_by('first_name');
}
$rs = $this->db->get();
if ($rs->num_rows() > 0)
{
foreach ($rs->result() as $row)
{
if ($short_name == TRUE)
$tmp[$row->user_id] = $row->username;
else
$tmp[$row->user_id] = $row->last_name . ', ' . $row->first_name;
}
}
return $tmp;
}
}
/* End of file event_model.php */
/* Location: models/event/event_model.php */
<?php
/**
* Event Lead Controller
*
**/
class Lead extends Controller
{
/**
* Class constructor
* @access public
* @param void
* @return void
* */
function Lead()
{
parent::Controller();
// Check if current user is logged in
$this->aa_auth->bouncer();
// Store user privileges in a local var (to use inside the controller)
$this->user_id = $this->session->userdata('user_id');
$this->user_acl = $this->aa_auth->refresh_auth(2);
// Store user privileges in a template var (to use inside views)
$this->template['user_acl'] = $this->user_acl;
$this->template['page_id'] = 'events';
$this->load->helper('url');
$this->load->library('pagination');
$this->load->library('layout');
$this->layout->set_layout('layout_main/index');
$this->load->helper('date');
$this->load->helper('text');
$this->load->model('user_model');
$this->load->model('misc_model');
$this->load->model('file_model');
$this->load->model('event/event_model', 'event_model');
$this->load->model('event/lead_model', 'lead_model');
$this->load->model('system/venue_model', 'venue_model');
$this->load->model('log_model', 'log_model');
if (($this->user_acl['superadmin'] === FALSE) || ($this->user_acl['admin'] === FALSE))
{
// Is not a superadmin or admin, means it is a manager or user,
// lets see if they have access to this app
if ($this->user_model->has_application($this->user_id, 'events') === FALSE)
{
$this->session->set_flashdata('flashmessage', 'You don\'t have access enabled to the event application.');
redirect('users/dashboard');
}
}
$this->template['h1_title'] = 'Event Manager';
$this->template['section_class'] = 'table manage';
$this->template['jscode_domready'] = '';
$page_nav['user_acl'] = $this->user_acl;
// Load the enabled venues
if (($this->user_acl['superadmin'] === FALSE) || ($this->user_acl['admin'] === FALSE))
{
$this->enabled_venues = $this->venue_model->get_venues_ddlist($this->user_id);
}
else
{
$this->enabled_venues = $this->venue_model->get_venues_ddlist();
}
}
/**
* Index
* @access public
* @param void
* @return void
* */
function index($_venue = 'all', $_user = 'all', $_period = 'all', $_si = 0, $_sort_by = 'date', $_sort_order = 'asc')
{
if ($this->input->post('btn_submit', TRUE))
{
$filter_venue = $this->input->post('filter_venue', TRUE);
$filter_user = $this->input->post('filter_user', TRUE);
$filter_period = $this->input->post('filter_period', TRUE);
if (trim($filter_venue) != '')
$_venue = (int) $filter_venue;
if (trim($filter_user) != '')
$_user = (int) $filter_user;
if (trim($filter_period) != '')
$_period = $filter_period;
}
$filter = array();
$vars = array();
$filter['event.event_client_approved'] = 'no';
// If the following happens, something wrong has been made
if (count($this->enabled_venues) > 1)
{
// enabled_venues holds the array suitable for use with dropdown, means, it has an
// extra element [NULL] = Please select bla bla, so, first, we extract all of the
// keys from that array and store it in venue_keys (it saves an additional empty item)
$venue_keys = array_keys($this->enabled_venues);
// Ok, now "we get" the first item into empty value, this way, we take out the first empty item
$empty = array_shift($venue_keys);
// now we have only real keys on venue_keys and we can send it to the model, which will turn the
// array into an where_in statement
}
$vars['filter']['venues'] = 'all';
if ($_venue == 'all')
{
$filter['event_version.event_venue'] = $venue_keys;
}
else
{
if (in_array($_venue, $venue_keys))
{
$filter['event_version.event_venue'] = $_venue;
$vars['filter']['venues'] = $_venue;
}
else
{
$filter['event_version.event_venue'] = $venue_keys;
}
}
$vars['filter']['user'] = $_user;
if ($_user !== 'all')
{
$filter['event.event_prepared_by'] = $_user;
}
$vars['filter']['period'] = $_period;
if ($_period !== 'all')
{
$month = str_pad(substr($_period, 0, 2), 2, '0', STR_PAD_LEFT);
$year = substr($_period, 2, 4);
$filter['EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = ' . $month] = NULL;
$filter['EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = ' . $year] = NULL;
}
else
{
$filter['EXTRACT(day FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) >= ' . date('d')] = NULL;
$filter['EXTRACT(month FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = ' . date('m')] = NULL;
$filter['EXTRACT(year FROM ADDTIME(FROM_UNIXTIME(event_version.event_date), event_version.event_start_time)) = ' . date('Y')] = NULL;
}
//make sure start index isn't too low
if ($_si < 0)
$_si = 0;
//set number of results, per page
$pp = 10;
$tr = $this->lead_model->get_total_records($filter);
//make sure start index isnt too high
$max_si = floor($tr / $pp) * $pp;
if ($_si > $max_si)
$_si = $max_si;
$config['base_url'] = base_url() . 'event/lead/index/' . $_venue . '/' . $_user . '/' . $_period;
$config['base_url_end'] = '/' . $_sort_by . '/' . $_sort_order;
$config['uri_segment'] = 7;
$config['total_rows'] = $tr;
$config['per_page'] = $pp;
$config['start_index'] = $_si;
$this->pagination->initialize($config);
$vars['limit']['offset'] = $_si;
$limit['limit'] = 10;
$limit['offset'] = $_si;
$vars['sort']['field'] = $_sort_by;
switch ($_sort_by)
{
case 'venue': $order['field'] = 'venue.venue_name';
break;
case 'name': $order['field'] = 'event_version.event_name';
break;
case 'date': $order['field'] = 'event_version.event_date';
break;
case 'type': $order['field'] = 'event_version.event_type';
break;
case 'people': $order['field'] = 'event_version.event_people';
break;
case 'minimum': $order['field'] = 'event_version.event_minimum_guarantee';
break;
default: $order['field'] = 'event_version.event_date';
break;
}
$order['order'] = $_sort_order;
if ($_sort_order == 'desc')
{
$vars['sort']['order'] = 'asc';
}
else if ($_sort_order == 'asc')
{
$vars['sort']['order'] = 'desc';
}
else
{
$vars['sort']['order'] = 'desc';
}
$css_files = array(
'assets/css/framework/forms.css',
'assets/css/sourced/smoothbox/smoothbox.css'
);
$this->template['css_files'] = asset_link($css_files, 'css');
$js_files = array(
'assets/js/sourced/tiny_mce/tiny_mce.js',
'assets/js/sourced/smoothbox/smoothbox.js',
'assets/js/framework/transitions.fx.js',
'assets/js/extensions/email.contract.js'
);
$this->template['js_files'] = asset_link($js_files, 'js');
$this->template['jscode'] = '
var site_url = "' . site_url() . '";
var updated_content = false;
initHtmlEmailEditor();
';
$vars['pagination_links'] = $this->pagination->create_links();
$vars['venues'] = $this->enabled_venues;
$vars['users'] = $this->event_model->get_users();
$vars['events'] = $this->lead_model->get_records($filter, $limit, $order);
$this->template['section_1_title'] = 'Pending Events/Reservation';
$this->template['section_1'] = $this->load->view('event/lead/main', $vars, TRUE);
$this->layout->view($this->template);
}
/**
* Index
* @access public
* @param void
* @return void
* */
function list_versions()
{
if ($this->uri->segment(4))
{
$event_id = $this->uri->segment(4);
$total_rows = $this->event_model->get_total_records(array('event.event_id' => $event_id));
$pag_config['base_url'] = site_url('event/lead/list_versions/');
$pag_config['total_rows'] = $total_rows;
$pag_config['per_page'] = 10;
$pag_config['uri_segment'] = 5;
$this->pagination->initialize($pag_config);
$limit['limit'] = $pag_config['per_page'];
if ($this->uri->segment(5))
$limit['offset'] = $this->uri->segment(5);
else
$limit['offset'] = 0;
$vars['pagination_links'] = $this->pagination->create_links();
// Show Leads Only
$filter['event.event_id'] = $event_id;
$filter['event.event_client_approved'] = 'no';
$vars['events'] = $this->lead_model->get_versions($filter, $limit);
$page = 'event/lead/versions';
$this->template['section_1_title'] = 'Event Leads Versions';
$this->template['section_1'] = $this->load->view($page, $vars, TRUE);
$this->layout->view($this->template);
}
else
redirect('event/lead');
}
/**
* Notify Users about Event related actions
*
* @access private
* @param array $data
* @param string $action
* @return void
* */
function _notify_users($data, $action = NULL)
{
$list = $this->user_model->get_notification_list($data['lead']->event_venue);
if ((count($list) > 0) && ($data['lead']->event_reservation == 'no'))
{
$data['url_login'] = site_url('user/login');
$data['url_site'] = base_url();
$data['venue_name'] = $this->lead_model->get_venue_name($data['lead']->event_venue);
$data['proposal_type'] = $data['lead']->event_reservation == 'yes' ? 'Reservation' : 'Proposal';
$subject = '[' . $data['venue_name'] . '] Signed contract received for "' . $data['lead']->event_name . '" (' . date('M d, Y', $data['lead']->event_date) . ')';
foreach ($list as $user)
{
if ($this->user_id == $user['user_id'])
continue;
$this->email->clear();
$this->email->from('sysadmin@domain.com', 'SysAdmin @ Company');
$this->email->reply_to('do_not_reply@domain.com', 'do_not_reply@domain.com');
$this->email->to($user['email'], $user['first_name'] . ' ' . $user['last_name']);
$this->email->subject($subject);
$this->email->message($this->load->view('email/event/new_event_html', array_merge($data, $user), TRUE));
$this->email->set_alt_message($this->load->view('email/event/new_event_text', array_merge($data, $user), TRUE));
$this->email->send();
}
}
}
/**
* Add a New Lead
* @access public
* @param void
* @return void
* */
function add()
{
if ($this->session->userdata('options_key'))
$options_key = $this->session->userdata('options_key');
else
{
$this->db->where('options_key', md5('Y-m-d' . $this->user_id));
$this->db->delete('event_options');
$this->session->set_userdata('options_key', md5('Y-m-d' . $this->user_id));
$options_key = $this->session->userdata('options_key');
}
if ($this->input->post('btn_clear_options'))
{
$this->db->where('options_key', md5('Y-m-d' . $this->user_id));
$this->db->delete('event_options');
}
if ($this->input->post('btn_delete_options'))
{
$options_to_delete = $this->input->post('delete_list');
if (count($options_to_delete) > 0)
{
foreach ($options_to_delete as $index => $option_id)
{
$this->db->where('option_id', $option_id);
$this->db->delete('event_options');
}
}
}
$this->fields['event_venue'] = 'venue';
$this->fields['event_name'] = 'event name';
$this->fields['event_contact_name'] = 'contact name';
$this->fields['event_contact_phone'] = 'contact phone';
$this->fields['event_contact_email'] = 'contact email';
$this->fields['event_date_year'] = 'event date year';
$this->fields['event_date_month'] = 'event date month';
$this->fields['event_date_day'] = 'event date day';
$this->fields['st_hour'] = 'start time hour';
$this->fields['st_minute'] = 'start time minute';
$this->fields['st_tc'] = 'start time time conversion';
$this->fields['et_hour'] = 'end time hour';
$this->fields['et_minute'] = 'end time minute';
$this->fields['et_tc'] = 'end time time conversion';
$this->fields['event_end_time'] = 'end time';
$this->fields['event_type'] = 'event type';
$this->fields['event_people'] = '# of people';
$this->fields['event_minimum_guarantee'] = 'minimum guarantee';
$this->fields['event_remarks'] = 'remarks';
$this->fields['event_details'] = 'details';
$this->rules['event_venue'] = 'trim|required';
$this->rules['event_name'] = 'trim';
$this->rules['event_contact_name'] = 'trim|required';
$this->rules['event_contact_phone'] = 'trim';
$this->rules['event_contact_email'] = 'trim|valid_email';
$this->rules['event_date_year'] = 'trim|required';
$this->rules['event_date_month'] = 'trim|required';
$this->rules['event_date_day'] = 'trim|required';
$this->rules['st_hour'] = 'trim|required|numeric';
$this->rules['st_minute'] = 'trim|required|numeric';
$this->rules['st_tc'] = 'trim|required';
$this->rules['et_hour'] = 'trim|required|numeric';
$this->rules['et_minute'] = 'trim|required|numeric';
$this->rules['et_tc'] = 'trim|required';
$this->rules['event_type'] = 'trim';
$this->rules['event_people'] = 'trim|required|numeric';
$this->rules['event_minimum_guarantee'] = 'trim|required|numeric';
$this->rules['event_remarks'] = 'trim|prep_for_form';
$this->rules['event_details'] = 'trim|prep_for_form';
if ($this->input->post('btn_add_option'))
{
$this->_add_option();
}
$this->validation->set_fields($this->fields);
$this->validation->set_rules($this->rules);
if ($this->validation->run() === TRUE)
{
// Add Option Button
if ($this->input->post('btn_add_option'))
{
$prepped['options_key'] = $this->input->post('options_key', TRUE);
$prepped['option_name'] = $this->input->post('option_name', TRUE);
$prepped['option_qty'] = $this->input->post('option_qty', TRUE);
$prepped['option_price'] = $this->input->post('option_price', TRUE);
$opt_hour = (int) $this->input->post('opt_hour', TRUE);
$opt_minute = (int) $this->input->post('opt_minute', TRUE);
$opt_tc = $this->input->post('opt_tc', TRUE);
if ((strtolower($opt_tc) == 'am') && ($opt_hour == 12))
$opt_hour = '00';
if ((strtolower($opt_tc) == 'pm') && ($opt_hour != 12))
$opt_hour += 12;
$prepped['option_time'] = $opt_hour . ':' . $opt_minute . ':00';
$prepped['option_total'] = $this->input->post('option_total', TRUE);
$prepped['option_description'] = $this->input->post('option_description', TRUE);
$options_type_desc = $this->input->post('option_type_desc');
if (is_array($options_type_desc))
$prepped['option_type_desc'] = implode('<br /> ', $options_type_desc);
else
$prepped['option_type_desc'] = '';
$otype['Drink Options'] = 'drink';
$prepped['option_type'] = isset($otype[$prepped['option_name']]) ? $otype[$prepped['option_name']] : 'food';
if (trim($prepped['option_qty']) == '')
$prepped['option_qty'] = $this->validation->event_minimum_guarantee;
if ($this->input->post('option_total') != '')
{
$prepped['option_subtotal'] = $prepped['option_qty'] * $prepped['option_price'];
}
else
{
$prepped['option_subtotal'] = $prepped['option_qty'] * $prepped['option_price'];
$prepped['option_total'] = $prepped['option_subtotal'];
}
$this->lead_model->add_orphan_option($prepped);
}
// Send Main Button
if ($this->input->post('btn_submit'))
{
// Main Event Information
$event['event_prepared_by'] = $this->user_id;
$event['event_created_on'] = now();
$event['event_latest_version'] = '0';
// Versioning Event Information
foreach ($this->fields as $field_name => $field_value)
{
$event_version[$field_name] = nl2br($this->validation->$field_name);
}
$event_version['event_modified_by'] = $this->user_id;
$event_version['event_modified_date'] = now();
$event_version['event_reservation'] = $this->input->post('event_reservation') ? 'yes' : 'no';
$event_version['event_is_tax_exempt'] = $this->input->post('event_is_tax_exempt') ? 'yes' : 'no';
// Add Event Lead, will return status and Event ID
$result = $this->lead_model->add_lead($event, $event_version, $options_key);
$event['event_id'] = $result['event_id'];
$event_version['event_version'] = $result['event_version'];
// Insert data into aList
$this->sync_with_alist($event_version);
if ($result['status'] === TRUE)
{
$this->session->unset_userdata('options_key');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'txt|doc|word|xl|rtf|zip|tar|ppt|xls|pdf|csv|gif|jpg|png';
$config['max_size'] = '30000';
$this->load->library('upload', $config);
if ($this->upload->do_upload('file'))
{
$data = $this->upload->data();
$data['user_id'] = $this->user_id;
$rs_file = $this->file_model->add($data);
if ($result['status'] == TRUE)
{
$efile['file_id'] = $rs_file['insert_id'];
$efile['event_id'] = $result['event_id'];
$efile['event_version'] = $result['event_version'];
$this->file_model->link_event($efile);
}
}
// Log
$log['user_id'] = $this->user_id;
$log['object_id'] = $result['event_id'];
$log['application'] = 'event manager';
$log['action'] = 'New Proposal for Event "' . $event_version['event_name'] . '" succesfully added.';
$this->log_model->add($log);
redirect('event/lead/options/' . $result['event_id'] . '/' . $result['event_version']);
} // end if
} // end if
} // end if
else
{
if ($this->input->post('btn_add_option') && trim(strip_tags($this->validation->error_string)) <> '')
$vars['add_option_error'] = $this->validation->error_string;
}
$js_files = array(
'assets/js/extensions/calendar.compat.js',
'assets/js/extensions/calendar.js',
'assets/js/extensions/event.fx.js',
'assets/js/framework/transitions.fx.js',
);
$this->template['js_files'] = asset_link($js_files, 'js');
$this->template['jscode_domready'].= "call_start_proposal();\n";
$filter['options_key'] = $options_key;
$options = $this->lead_model->get_options($filter);
$options_totals = $this->lead_model->get_options_totals($filter);
$otvars['options'] = $options;
$opvars['options_totals'] = $options_totals;
$opvars['venue_tax'] = $this->lead_model->get_venue_tax($this->input->post('event_venue'));
$vars['options_table'] = $this->load->view('event/lead/add_option_list', $otvars, TRUE);
$vars['options_prices'] = $this->load->view('event/lead/add_option_prices', $opvars, TRUE);
$vars['venues'] = $this->enabled_venues;
$vars['options_key'] = $options_key;
$vars['_options'] = $this->lead_model->get_food_options();
// Get arrays for the dropdowns
$vars['years'] = $this->misc_model->get_years();
$vars['months'] = $this->misc_model->get_months();
$vars['days'] = $this->misc_model->get_days();
$vars['hours'] = $this->misc_model->get_hours();
$vars['minutes'] = $this->misc_model->get_minutes();
$vars['tc'] = $this->misc_model->get_tc();
$vars['options_names'] = $this->misc_model->get_options_names();
$lb_data['menu_titles'] = $this->lead_model->get_menu_titles();
$this->template['lightbox_holder'] = $this->load->view('event/lead/lb_manage_menu', $lb_data, TRUE);
$this->template['section_1_title'] = 'Event Lead - New Proposal';
$this->template['section_1'] = $this->load->view('event/lead/add', $vars, TRUE);
$this->layout->view($this->template);
}
/**
* Handle JSON Add Option
* @access public
* @param void
* @return void
* */
function json_add_option()
{
if ($this->session->userdata('options_key'))
$options_key = $this->session->userdata('options_key');
else
{
$this->db->where('options_key', md5('Y-m-d' . $this->user_id));
$this->db->delete('event_options');
$this->session->set_userdata('options_key', md5('Y-m-d' . $this->user_id));
$options_key = $this->session->userdata('options_key');
}
$this->fields['event_people'] = '# of people';
$this->fields['event_minimum_guarantee'] = 'minimum guarantee';
$this->fields['options_key'] = 'option key';
$this->fields['option_name'] = 'name';
$this->fields['opt_hour'] = 'hour';
$this->fields['opt_minute'] = 'minute';
$this->fields['opt_tc'] = 'time conversion';
$this->fields['option_qty'] = 'quantity';
$this->fields['option_price'] = 'price';
$this->fields['option_total'] = 'total';
$this->fields['option_description'] = 'description';
$this->rules['event_people'] = 'trim|required|numeric';
$this->rules['event_minimum_guarantee'] = 'trim|required|numeric';
$this->rules['options_key'] = 'trim|required|callback__check_fields';
$this->rules['option_name'] = 'trim|required';
$this->rules['opt_hour'] = 'trim|required';
$this->rules['opt_minute'] = 'trim|required';
$this->rules['opt_tc'] = 'trim|required';
$this->rules['option_qty'] = 'trim';
$this->rules['option_price'] = 'trim';
$this->rules['option_total'] = 'trim';
$this->rules['option_description'] = 'trim';
$this->validation->set_fields($this->fields);
$this->validation->set_rules($this->rules);
if ($this->validation->run() === TRUE)
{
$otype = $this->misc_model->get_options_types();
$prepped['options_key'] = $this->input->post('options_key', TRUE);
$prepped['option_name'] = $this->input->post('option_name', TRUE);
$prepped['option_qty'] = $this->input->post('option_qty', TRUE);
$prepped['option_price'] = $this->input->post('option_price', TRUE);
$opt_hour = (int) $this->input->post('opt_hour', TRUE);
$opt_minute = (int) $this->input->post('opt_minute', TRUE);
$opt_tc = $this->input->post('opt_tc', TRUE);
if ((strtolower($opt_tc) == 'am') && ($opt_hour == 12))
$opt_hour = '00';
if ((strtolower($opt_tc) == 'pm') && ($opt_hour != 12))
$opt_hour += 12;
$prepped['option_time'] = $opt_hour . ':' . $opt_minute . ':00';
$prepped['option_total'] = $this->input->post('option_total', TRUE);
$prepped['option_description'] = $this->input->post('option_description', TRUE);
$options_type_desc = $this->input->post('option_type_desc');
if (is_array($options_type_desc))
$prepped['option_type_desc'] = implode('<br /> ', $options_type_desc);
else
$prepped['option_type_desc'] = '';
$otype['Drink Options'] = 'drink';
$prepped['option_type'] = isset($otype[$prepped['option_name']]) ? $otype[$prepped['option_name']] : 'food';
if (trim($prepped['option_qty']) == '')
$prepped['option_qty'] = $this->validation->event_minimum_guarantee;
if ($this->input->post('option_total') != '')
$prepped['option_subtotal'] = $prepped['option_qty'] * $prepped['option_price'];
else
{
$prepped['option_subtotal'] = $prepped['option_qty'] * $prepped['option_price'];
$prepped['option_total'] = $prepped['option_subtotal'];
}
$status = $this->lead_model->add_orphan_option($prepped);
if ($status['result'] == TRUE)
{
$record->status = 'success';
$filter['options_key'] = $options_key;
$data['options'] = $this->lead_model->get_options($filter);
$record->updated_options_content = $this->load->view('event/lead/add_option_list_json', $data, TRUE);
}
else
{
$record->status = 'error';
$record->error_message = 'We found an error processing your request, please try again later.';
}
}
else
{
$record->status = 'error';
$record->error_message = strip_tags($this->validation->error_string);
}
echo json_encode($record);
}
/**
* Handle JSON Delete Option
* @access public
* @param void
* @return void
* */
function json_delete_option()
{
if ($this->session->userdata('options_key'))
$options_key = $this->session->userdata('options_key');
else
{
$this->db->where('options_key', md5('Y-m-d' . $this->user_id));
$this->db->delete('event_options');
$this->session->set_userdata('options_key', md5('Y-m-d' . $this->user_id));
$options_key = $this->session->userdata('options_key');
}
$tmp = array();
if ($this->input->post('btn_delete_options'))
{
$options_to_delete = $this->input->post('delete_list');
if (count($options_to_delete) > 0)
{
foreach ($options_to_delete as $index => $option_id)
{
$this->db->where('option_id', $option_id);
$this->db->delete('event_options');
}
$filter['options_key'] = $options_key;
$data['options'] = $this->lead_model->get_options($filter);
$record->updated_options_content = $this->load->view('event/lead/add_option_list_json', $data, TRUE);
$record->status = 'success';
}
else
{
$record->status = 'error';
$record->error_message = 'Nothing to process, please select the options you want to delete.';
}
}
else
{
$record->status = 'error';
$record->error_message = 'Nothing to process, please select the options you want to delete.';
}
echo json_encode($record);
}
/**
* Define validation fields and rules for the add option form
* @access public
* @param void
* @return void
* */
function _add_option()
{
// Fields for the Add Option Form
$this->fields['options_key'] = 'option key';
$this->fields['option_name'] = 'name';
$this->fields['opt_hour'] = 'hour';
$this->fields['opt_minute'] = 'minute';
$this->fields['opt_tc'] = 'time conversion';
$this->fields['option_qty'] = 'quantity';
$this->fields['option_price'] = 'price';
$this->fields['option_total'] = 'total';
$this->fields['option_description'] = 'description';
$this->rules['options_key'] = 'trim|required|callback__check_fields';
$this->rules['option_name'] = 'trim|required';
$this->rules['opt_hour'] = 'trim|required';
$this->rules['opt_minute'] = 'trim|required';
$this->rules['opt_tc'] = 'trim|required';
$this->rules['option_qty'] = 'trim';
$this->rules['option_price'] = 'trim';
$this->rules['option_total'] = 'trim';
$this->rules['option_description'] = 'trim';
}
/**
* Check to ensure at least one of the three main fields have data
* @access private
* @param string
* @return boolean
* */
function _check_fields($str)
{
if (trim($this->validation->option_qty) <> '')
return TRUE;
if (trim($this->validation->option_price) <> '')
return TRUE;
if (trim($this->validation->option_total) <> '')
return TRUE;
$this->validation->set_message('_check_fields', 'You need to enter at least one of the following fields: Quantity, Price or Total.');
return FALSE;
}
/**
* Edit Lead
* @access public
* @param void
* @return void
* */
function edit()
{
if ($this->uri->segment(4) && $this->uri->segment(5))
{
$event_id = $this->uri->segment(4);
$event_version = $this->uri->segment(5);
$filter['event.event_id'] = $event_id;
$filter['event_version.event_version'] = $event_version;
$lead = $this->lead_model->get_lead($filter);
$fields['event_id'] = 'event id';
$fields['event_version'] = 'event version';
$fields['event_venue'] = 'venue';
$fields['event_name'] = 'event name';
$fields['event_contact_name'] = 'contact name';
$fields['event_contact_phone'] = 'contact phone';
$fields['event_contact_email'] = 'contact email';
$fields['event_date_year'] = 'event date year';
$fields['event_date_month'] = 'event date month';
$fields['event_date_day'] = 'event date day';
$fields['st_hour'] = 'start time hour';
$fields['st_minute'] = 'start time minute';
$fields['st_tc'] = 'start time time conversion';
$fields['et_hour'] = 'end time hour';
$fields['et_minute'] = 'end time minute';
$fields['et_tc'] = 'end time time conversion';
$fields['event_type'] = 'event type';
$fields['event_people'] = '# of people';
$fields['event_minimum_guarantee'] = 'minimum guarantee';
$fields['event_remarks'] = 'remarks';
$fields['event_details'] = 'details';
$fields['event_is_tax_exempt'] = 'tax exempt';
$this->validation->set_fields($fields);
$rules['event_id'] = 'trim|required';
$rules['event_version'] = 'trim|required';
$rules['event_venue'] = 'trim|required';
$rules['event_name'] = 'trim|required';
$rules['event_contact_name'] = 'trim|required';
$rules['event_contact_phone'] = 'trim';
$rules['event_contact_email'] = 'trim|required|valid_email';
$rules['event_date_year'] = 'trim|required';
$rules['event_date_month'] = 'trim|required';
$rules['event_date_day'] = 'trim|required';
$rules['st_hour'] = 'trim|required|numeric';
$rules['st_minute'] = 'trim|required|numeric';
$rules['st_tc'] = 'trim|required';
$rules['et_hour'] = 'trim|required|numeric';
$rules['et_minute'] = 'trim|required|numeric';
$rules['et_tc'] = 'trim|required';
$rules['event_type'] = 'trim|required';
$rules['event_people'] = 'trim|required|numeric';
$rules['event_minimum_guarantee'] = 'trim|required|numeric';
$rules['event_remarks'] = 'trim|prep_for_form';
$rules['event_details'] = 'trim|prep_for_form';
$rules['event_is_tax_exempt'] = 'trim';
$this->validation->set_rules($rules);
if ($this->validation->run() === TRUE)
{
// Versioning Event Information
foreach ($fields as $field_name => $field_value)
{
$data[$field_name] = nl2br($this->validation->$field_name);
}
if (!isset($data['event_is_tax_exempt']) ||
trim($data['event_is_tax_exempt']) == '')
$data['event_is_tax_exempt'] = 'no';
$data['event_modified_by'] = $this->user_id;
$data['event_modified_date'] = now();
$where['event_id'] = $event_id;
$where['event_version'] = $event_version;
// Edit Event Lead
$result = $this->lead_model->edit($data, $where);
if ($result['status'] === TRUE)
{
foreach ($fields as $field_name => $field_value)
{
if ($data[$field_name] != $lead->$field_name)
{
$log_action = str_replace('event_', '', $field_name);
$log_action = str_replace('date_', '', $log_action);
$log_action = str_replace('st_', '', $log_action);
$log_action = str_replace('et_', '', $log_action);
$log_action = str_replace('_', ' ', $log_action);
switch ($log_action)
{
case 'name':
$log_action = 'EVENT NAME';
break;
case 'year':
$log_action = 'DATE';
break;
case 'month':
$log_action = 'DATE';
break;
case 'day':
$log_action = 'DATE';
break;
case 'hour':
$log_action = 'TIME';
break;
case 'minute':
$log_action = 'TIME';
break;
case 'tc':
$log_action = 'TIME';
break;
case 'type':
$log_action = 'EVENT TYPE';
break;
case 'people':
$log_action = '# OF PEOPLE';
break;
case 'minimum guarantee':
$log_action = '# OF PEOPLE';
break;
default: strtoupper($log_action);
}
// Log changes
$log['user_id'] = $this->user_id;
$log['object_id'] = $result['event_id'];
$log['application'] = 'event manager';
$log['action'] = 'has changed the ' . strtoupper($log_action) . ' of the';
if (in_array($log_action, array('# OF PEOPLE', 'DATE', 'TIME')))
{
$this->log_model->add($log);
}
}
}
$this->session->set_flashdata('flashmessage', 'A new version of this proposal has been created!');
redirect('event/lead/options/' . $result['event_id'] . '/' . $result['event_version']);
}
else
{
$this->session->set_flashdata('flashmessage', 'There was an error processing your request!');
redirect('event/lead');
}
}
foreach ($fields as $field_name => $field_value)
{
if ($field_name == 'event_date')
$this->validation->$field_name = date('Y-m-d', $lead->$field_name);
else
$this->validation->$field_name = strip_tags($lead->$field_name);
}
$vars['venues'] = $this->enabled_venues;
$vars['event_id'] = $event_id;
$vars['event_version'] = $event_version;
$vars['years'] = $this->misc_model->get_years();
$vars['months'] = $this->misc_model->get_months();
$vars['days'] = $this->misc_model->get_days();
$page = 'event/lead/edit';
$this->template['section_1_title'] = 'Event Lead - Edit Proposal';
$this->template['section_1'] = $this->load->view($page, $vars, TRUE);
$css_files = array('assets/css/framework/forms.css');
$this->template['css_files'] = asset_link($css_files, 'css');
$js_files = array(
'assets/js/extensions/calendar.js',
'assets/js/extensions/calendar.compat.js',
'assets/js/framework/multiselect.fx.js',
'assets/js/framework/transitions.fx.js',
'assets/js/framework/validation.fx.js'
);
$this->template['js_files'] = asset_link($js_files, 'js');
$domready = "
//calendar = new Calendar({ event_date: 'Y-m-d' }, { classes: ['dashboard'], direction: 1 });
// Drop Down Code
change_drop_down('dd_event_date_day', 'dd_event_date_day_label');
change_drop_down('dd_event_date_month', 'dd_event_date_month_label');
change_drop_down('dd_event_date_year', 'dd_event_date_year_label');
change_drop_down('dd_venue', 'dd_venue_label');
change_drop_down('dd_st_hour', 'dd_st_hour_label');
change_drop_down('dd_st_minute', 'dd_st_minute_label');
change_drop_down('dd_st_tc', 'dd_st_tc_label');
change_drop_down('dd_et_hour', 'dd_et_hour_label');
change_drop_down('dd_et_minute', 'dd_et_minute_label');
change_drop_down('dd_et_tc', 'dd_et_tc_label');
";
$this->template['jscode_domready'].= $domready;
$this->layout->view($this->template);
}
}
/**
* Replicate Lead
* @access public
* @param void
* @return void
* */
function replicate()
{
if ($this->uri->segment(4) && $this->uri->segment(5))
{
$event_id = $this->uri->segment(4);
$event_version = $this->uri->segment(5);
$filter['event.event_id'] = $event_id;
$filter['event_version.event_version'] = $event_version;
$lead = $this->lead_model->get_lead($filter);
$fields['event_id'] = 'event id';
$fields['event_version'] = 'event version';
$fields['event_venue'] = 'venue';
$fields['event_name'] = 'event name';
$fields['event_contact_name'] = 'contact name';
$fields['event_contact_phone'] = 'contact phone';
$fields['event_contact_email'] = 'contact email';
$fields['event_date_year'] = 'event date year';
$fields['event_date_month'] = 'event date month';
$fields['event_date_day'] = 'event date day';
$fields['st_hour'] = 'start time hour';
$fields['st_minute'] = 'start time minute';
$fields['st_tc'] = 'start time time conversion';
$fields['et_hour'] = 'end time hour';
$fields['et_minute'] = 'end time minute';
$fields['et_tc'] = 'end time time conversion';
$fields['event_type'] = 'event type';
$fields['event_people'] = '# of people';
$fields['event_minimum_guarantee'] = 'minimum guarantee';
$fields['event_remarks'] = 'remarks';
$fields['event_details'] = 'details';
$fields['event_is_tax_exempt'] = 'tax exempt';
$this->validation->set_fields($fields);
$rules['event_id'] = 'trim|required';
$rules['event_version'] = 'trim|required';
$rules['event_venue'] = 'trim|required';
$rules['event_name'] = 'trim|required';
$rules['event_contact_name'] = 'trim|required';
$rules['event_contact_phone'] = 'trim';
$rules['event_contact_email'] = 'trim|required|valid_email';
$rules['event_date_year'] = 'trim|required';
$rules['event_date_month'] = 'trim|required';
$rules['event_date_day'] = 'trim|required';
$rules['st_hour'] = 'trim|required|numeric';
$rules['st_minute'] = 'trim|required|numeric';
$rules['st_tc'] = 'trim|required';
$rules['et_hour'] = 'trim|required|numeric';
$rules['et_minute'] = 'trim|required|numeric';
$rules['et_tc'] = 'trim|required';
$rules['event_type'] = 'trim|required';
$rules['event_people'] = 'trim|required|numeric';
$rules['event_minimum_guarantee'] = 'trim|required|numeric';
$rules['event_remarks'] = 'trim|prep_for_form';
$rules['event_details'] = 'trim|prep_for_form';
$rules['event_is_tax_exempt'] = 'trim';
$this->validation->set_rules($rules);
if ($this->validation->run() === TRUE)
{
// Versioning Event Information
foreach ($fields as $field_name => $field_value)
{
$data[$field_name] = nl2br($this->validation->$field_name);
}
if (!isset($data['event_is_tax_exempt']) ||
(trim($data['event_is_tax_exempt']) == ''))
$data['event_is_tax_exempt'] = 'no';
$data['event_modified_by'] = $this->user_id;
$data['event_modified_date'] = now();
$where['event_id'] = $event_id;
$where['event_version'] = $event_version;
// Edit Event Lead
$result = $this->lead_model->replicate($data, $where);
if ($result['status'] === TRUE)
{
$this->session->set_flashdata('flashmessage', 'A new version of this proposal has been replicated!');
redirect('event/lead/options/' . $result['event_id'] . '/' . $result['event_version']);
}
else
{
$this->session->set_flashdata('flashmessage', 'There was an error processing your request!');
redirect('event/lead');
}
}
foreach ($fields as $field_name => $field_value)
{
if ($field_name == 'event_date')
$this->validation->$field_name = date('Y-m-d', $lead->$field_name);
else
$this->validation->$field_name = strip_tags($lead->$field_name);
}
$vars['venues'] = $this->enabled_venues;
$vars['event_id'] = $event_id;
$vars['event_version'] = $event_version;
$vars['years'] = $this->misc_model->get_years();
$vars['months'] = $this->misc_model->get_months();
$vars['days'] = $this->misc_model->get_days();
$page = 'event/lead/edit';
$this->template['section_1_title'] = 'Event Lead - Replicate Proposal';
$this->template['section_1'] = $this->load->view($page, $vars, TRUE);
$css_files = array('assets/css/framework/forms.css');
$this->template['css_files'] = asset_link($css_files, 'css');
$js_files = array(
'assets/js/extensions/calendar.js',
'assets/js/extensions/calendar.compat.js',
'assets/js/framework/multiselect.fx.js',
'assets/js/framework/transitions.fx.js',
'assets/js/framework/validation.fx.js'
);
$this->template['js_files'] = asset_link($js_files, 'js');
$domready = "
change_drop_down('dd_event_date_day', 'dd_event_date_day_label');
change_drop_down('dd_event_date_month', 'dd_event_date_month_label');
change_drop_down('dd_event_date_year', 'dd_event_date_year_label');
change_drop_down('dd_venue', 'dd_venue_label');
change_drop_down('dd_st_hour', 'dd_st_hour_label');
change_drop_down('dd_st_minute', 'dd_st_minute_label');
change_drop_down('dd_st_tc', 'dd_st_tc_label');
change_drop_down('dd_et_hour', 'dd_et_hour_label');
change_drop_down('dd_et_minute', 'dd_et_minute_label');
change_drop_down('dd_et_tc', 'dd_et_tc_label');
";
$this->template['jscode_domready'].= $domready;
$this->layout->view($this->template);
}
}
/**
* Manage Option Leads
* @access public
* @param void
* @return void
* */
function options()
{
if ($this->uri->segment(4) && $this->uri->segment(5))
{
$event_id = $this->uri->segment(4);
$event_version = $this->uri->segment(5);
$filter['event.event_id'] = $event_id;
$filter['event_version.event_version'] = $event_version;
$lead = $this->lead_model->get_record($filter);
unset($filter);
$fields['event_id'] = 'event id';
$fields['event_version'] = 'event version';
$fields['option_name'] = 'name';
$fields['opt_hour'] = 'hour';
$fields['opt_minute'] = 'minute';
$fields['opt_tc'] = 'time conversion';
$fields['option_qty'] = 'quantity';
$fields['option_price'] = 'price';
$fields['option_total'] = 'total';
$fields['option_description'] = 'description';
$this->validation->set_fields($fields);
$rules['event_id'] = 'trim|required|callback__check_fields';
$rules['event_version'] = 'trim|required';
$rules['option_name'] = 'trim|required';
$rules['opt_hour'] = 'trim|required';
$rules['opt_minute'] = 'trim|required';
$rules['opt_tc'] = 'trim|required';
$rules['option_qty'] = 'trim';
$rules['option_price'] = 'trim';
$rules['option_total'] = 'trim';
$rules['option_description'] = 'trim';
$this->validation->set_rules($rules);
/**
ADD OPTION BUTTON PRESSED
* */
if ($this->input->post('btn_add_option') && ($this->validation->run() === TRUE))
{
$otype = $this->misc_model->get_options_types();
$prepped['event_id'] = $this->input->post('event_id', TRUE);
$prepped['event_version'] = $this->input->post('event_version', TRUE);
$prepped['option_name'] = $this->input->post('option_name', TRUE);
$prepped['option_qty'] = $this->input->post('option_qty', TRUE);
$prepped['option_price'] = $this->input->post('option_price', TRUE);
$opt_hour = (int) $this->input->post('opt_hour', TRUE);
$opt_minute = (int) $this->input->post('opt_minute', TRUE);
$opt_tc = $this->input->post('opt_tc', TRUE);
if ((strtolower($opt_tc) == 'am') && ($opt_hour == 12))
$opt_hour = '00';
if ((strtolower($opt_tc) == 'pm') && ($opt_hour != 12))
$opt_hour += 12;
$prepped['option_time'] = $opt_hour . ':' . $opt_minute . ':00';
$prepped['option_total'] = $this->input->post('option_total', TRUE);
$prepped['option_description'] = $this->input->post('option_description', TRUE);
$options_type_desc = $this->input->post('option_type_desc');
if (is_array($options_type_desc))
$prepped['option_type_desc'] = implode('<br /> ', $options_type_desc);
else
$prepped['option_type_desc'] = '';
$otype['Drink Options'] = 'drink';
$prepped['option_type'] = isset($otype[$prepped['option_name']]) ? $otype[$prepped['option_name']] : 'food';
if (trim($prepped['option_qty']) == '')
$prepped['option_qty'] = $this->validation->event_minimum_guarantee;
if ($this->input->post('option_total') != '')
{
$prepped['option_subtotal'] = $prepped['option_qty'] * $prepped['option_price'];
}
else
{
$prepped['option_subtotal'] = $prepped['option_qty'] * $prepped['option_price'];
$prepped['option_total'] = $prepped['option_subtotal'];
}
$this->lead_model->add_option($prepped);
$log['user_id'] = $this->user_id;
$log['object_id'] = $event_id;
$log['application'] = 'event manager';
$log['action'] = 'has added a(n) ' . strtoupper($prepped['option_type']) . ' menu to the';
$this->log_model->add($log);
redirect('event/lead/options/' . $event_id . '/' . $event_version);
}
/**
ATTACH FILE
* */
$vars['file_upload_error'] = '';
if ($this->input->post('btn_attach_file'))
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'txt|doc|word|xl|rtf|zip|tar|ppt|xls|pdf|csv|gif|jpg|png';
$config['max_size'] = '30000';
$this->load->library('upload', $config);
if ($this->upload->do_upload('file'))
{
$data = $this->upload->data();
$data['user_id'] = $this->user_id;
$result = $this->file_model->add($data);
if ($result['status'] == TRUE)
{
$efile['file_id'] = $result['insert_id'];
$efile['event_id'] = $event_id;
$efile['event_version'] = $event_version;
$this->file_model->link_event($efile);
}
}
else
{
$vars['file_upload_error'] = $this->upload->display_errors();
}
}
$filter['event_id'] = $event_id;
$filter['event_version'] = $event_version;
$options = $this->lead_model->get_options($filter);
$options_totals = $this->lead_model->get_options_totals($filter);
$vars['lead'] = $lead;
$vars['options'] = $options;
$vars['options_totals'] = $options_totals;
$vars['venues'] = $this->enabled_venues;
$vars['options_types'] = $this->lead_model->get_options_types();
$vars['food_types'] = $this->lead_model->get_food_types();
$vars['options_names'] = $this->misc_model->get_options_names();
$vars['_options'] = $this->lead_model->get_food_options();
$vars['event_files'] = $this->file_model->get_event_files($event_id, $event_version);
$vars['event_id'] = $event_id;
$vars['event_version'] = $event_version;
/**
EVENT HEADER INFORMATION
* */
$page = 'event/lead/lead_info';
if ($lead->event_client_approved == 'yes')
{
$this->template['h1_title'] = 'Event Manager / Contracts';
$this->template['section_1_title'] = 'Contract for ' . $lead->event_name;
}
else
{
$this->template['h1_title'] = 'Event Manager / Leads';
$this->template['section_1_title'] = 'Proposal for ' . $lead->event_name;
}
$vars['user_acl'] = $this->template['user_acl'];
$this->template['section_1'] = $this->load->view($page, $vars, TRUE);
$options_listing_title = 'section_2_title';
$options_listing_body = 'section_2';
$this->template[$options_listing_title] = 'Contract Options';
$options_listing_title = 'section_3_title';
$options_listing_body = 'section_3';
/**
ADD EVENT OPTIONS FORM
* */
$page = 'event/lead/add_option';
$this->template['section_2_title'] = 'Add Options';
$this->template['section_2'] = $this->load->view($page, $vars, TRUE);
$this->template['section_class'] = 'view';
$this->template[$options_listing_title] = 'Proposal Options';
/**
EVENT OPTIONS LISTING
* */
$page = 'event/lead/option_list';
$vars['event_id'] = $event_id;
$vars['event_version'] = $event_version;
$vars['venue_tax'] = $this->lead_model->get_venue_tax($lead->event_venue);
$this->template[$options_listing_body] = $this->load->view($page, $vars, TRUE);
$css_files = array(
'assets/css/framework/forms.css',
'assets/css/sourced/smoothbox/smoothbox.css'
);
$this->template['css_files'] = asset_link($css_files, 'css');
$js_files = array(
'assets/js/sourced/tiny_mce/tiny_mce.js',
'assets/js/sourced/smoothbox/smoothbox.js',
'assets/js/framework/multiselect.fx.js',
'assets/js/framework/transitions.fx.js',
'assets/js/extensions/event.fx.js',
'assets/js/framework/validation.fx.js',
'assets/js/extensions/email.contract.js'
);
$this->template['js_files'] = asset_link($js_files, 'js');
$this->template['jscode'] = '
var site_url = "' . site_url() . '";
var updated_content = false;
initHtmlEmailEditor();
';
$this->template['jscode_domready'].= "call_proposal_options();\n";
$lb_data['menu_titles'] = $this->lead_model->get_menu_titles();
$this->template['lightbox_holder'] = $this->load->view('event/lead/lb_manage_menu', $lb_data, TRUE);
$this->layout->view($this->template);
}
else
redirect('event/lead');
}
function json_remove_file()
{
if ($this->input->post('ids', TRUE))
{
$ids = explode('|', $this->input->post('ids', TRUE));
$this->file_model->delete_from_version($ids[0], $ids[1], $ids[2]);
$record->status = 'success';
}
else
{
$record->status = 'error';
$record->error_message = 'Error processing your request.';
}
echo json_encode($record);
}
function json_shift_time()
{
if ($this->input->post('event_id'))
{
$event_id = $this->input->post('event_id', TRUE);
$event_version = $this->input->post('event_version', TRUE);
$shift_type = $this->input->post('shift_type', TRUE);
$shift_time = $this->input->post('shift_time', TRUE);
if ($shift_type == 'inc')
{
$log_action = 'increasing';
$new_time = $shift_time;
}
else
{
$log_action = 'decreasing';
$new_time = '-' . $shift_time;
}
$this->db->set('option_time', "ADDTIME(option_time, '" . $new_time . "')", FALSE);
$this->db->where('event_id', $event_id);
$this->db->where('event_version', $event_version);
$this->db->update('event_options');
// Log this action
$log['user_id'] = $this->user_id;
$log['object_id'] = $event_id;
$log['application'] = 'event manager';
$log['action'] = 'has shifted the time ' . $log_action . ' by ' . $shift_time . ' to the';
//$this->log_model->add($log);
$filter['event_id'] = $event_id;
$filter['event_version'] = $event_version;
$data['options'] = $this->lead_model->get_options($filter);
$record->payload = $this->load->view('event/lead/option_list_ajax', $data, TRUE);
$record->status = 'success';
}
else
{
$record->status = 'error';
$record->error_message = 'Nothing to process, please select the options you want to delete.';
}
echo json_encode($record);
}
/**
* Generate a PDF Version of the proposal
* @access public
* @param void
* @return void
* */
function get_as_pdf()
{
if ($this->uri->segment(4) && $this->uri->segment(5))
{
$type = 'internal';
if ($this->uri->segment(6))
$type = 'client';
$this->load->helper(array('file', 'url'));
$this->load->library('LibPdf', 'libpdf');
$event_id = $this->uri->segment(4);
$event_version = $this->uri->segment(5);
$this->libpdf->build_proposal($event_id, $event_version, $type);
}
else
redirect('event/lead');
}
/**
* Generate a New Lead Version
* @access public
* @param void
* @return void
* */
function new_version()
{
if ($this->input->post('event_id'))
{
$event_id = $this->input->post('event_id');
$event_version = $this->input->post('event_version');
$result = $this->lead_model->generate_new_version($event_id, $event_version);
redirect('event/lead/options/' . $result['event_id'] . '/' . $result['event_version']);
}
else
redirect('event/lead');
}
/**
* Generate a New Lead Version
* @access public
* @param void
* @return void
* */
function approve()
{
if ($this->uri->segment(4))
$event_id = $this->uri->segment(4);
if ($this->input->post('event_id'))
$event_id = $this->input->post('event_id');
if ($this->uri->segment(5))
$event_version = $this->uri->segment(5);
if ($this->input->post('event_version'))
$event_version = $this->input->post('event_version');
if (isset($event_id) && isset($event_version))
{
$result = $this->lead_model->approve_lead($event_id, $event_version);
$ndata['lead'] = $this->lead_model->get_lead(array('event.event_id' => $event_id, 'event_version.event_version' => $event_version));
$ndata['lead_options'] = $this->lead_model->get_options(array('event_id' => $event_id, 'event_version' => $event_version));
$ndata['lead_totals'] = $this->lead_model->get_options_totals(array('event_id' => $event_id, 'event_version' => $event_version));
$ndata['user'] = $this->user_model->get_user_data(array('user_id' => $ndata['lead']->event_modified_by));
$this->_notify_users($ndata);
redirect('event/lead/options/' . $event_id . '/' . $event_version);
}
else
redirect('event/lead');
}
/**
* Delete Entire Event
* @access public
* @param void
* @return void
* */
function delete()
{
if ($this->input->post('event_id'))
{
$event_id = $this->input->post('event_id');
$this->lead_model->delete_event($event_id, $event_version);
$this->session->set_flashdata('flashmessage', 'Event #' . $event_id . ' was successfully deleted.');
}
redirect('event/dashboard');
}
/**
* Delete Lead Version
* @access public
* @param void
* @return void
* */
function delete_version()
{
if ($this->input->post('event_id'))
{
$event_id = $this->input->post('event_id');
$event_version = $this->input->post('event_version');
$result = $this->lead_model->delete_version($event_id, $event_version);
if (count($result) == 0)
redirect('event/lead');
else
redirect('event/lead/options/' . $result['event_id'] . '/' . $result['event_version'] . '/#section2');
}
else
redirect('event/lead');
}
/**
* Delete Lead Option
* @access public
* @param void
* @return void
* */
function delete_option()
{
if ($this->uri->segment(4))
{
$option_id = $this->uri->segment(4);
$option = $this->lead_model->get_option($option_id);
$result = $this->lead_model->delete_option($option_id);
// Log this action
if ($option !== FALSE)
{
$log['user_id'] = $this->user_id;
$log['object_id'] = $result['event_id'];
$log['application'] = 'event manager';
$log['action'] = 'has changed the ' . strtoupper($option->option_type) . ' menu of the';
$this->log_model->add($log);
}
redirect('event/lead/options/' . $result['event_id'] . '/' . $result['event_version']);
}
else
redirect('event/lead');
}
/**
* Switch Contract Tax Status to Tax Exempt or Taxed
*
* @param int $event_id
* @param int $event_version
* @param string $is_tax_exempt
*/
function is_tax_exempt($event_id, $event_version, $is_tax_exempt)
{
if ($this->input->server('HTTP_REFERER'))
$go_to = $this->input->server('HTTP_REFERER');
else
$go_to = site_url('event/dashboard');
if (($event_id == NULL) ||
($event_version == NULL) ||
($is_tax_exempt == NULL))
{
header('Location: ' . $go_to);
return;
}
$this->lead_model->tax_status($event_id, $event_version, $is_tax_exempt);
$go_to = site_url('event/lead/options/' . $event_id . '/' . $event_version);
if ($is_tax_exempt == 'yes')
$this->session->set_flashdata('flashmessage', 'This contract/proposal is now Tax Exempt.');
else
$this->session->set_flashdata('flashmessage', 'This contract/proposal is now Taxed.');
header('Location: ' . $go_to);
}
/**
* Defines that a Deposit has been taken for the given Event ID
* @access public
* @param void
* @return void
* */
function deposit_taken()
{
if ($this->input->server('HTTP_REFERER'))
$go_to = $this->input->server('HTTP_REFERER');
else
$go_to = site_url('event/dashboard/list_view');
if ($this->uri->segment(4))
{
$event_id = $this->uri->segment(4);
$this->lead_model->deposit_taken($event_id);
$this->session->set_flashdata('flashmessage', 'A Deposit has been made for Event #' . $event_id);
}
else
$this->session->set_flashdata('flashmessage', 'There was an error processing your request...');
header('Location: ' . $go_to);
}
/**
* Defines that a Balance is owed for the given Event ID
* @access public
* @param void
* @return void
* */
function balance_owed()
{
if ($this->input->server('HTTP_REFERER'))
$go_to = $this->input->server('HTTP_REFERER');
else
$go_to = site_url('event/dashboard/list_view');
if ($this->uri->segment(4))
{
$event_id = $this->uri->segment(4);
$this->lead_model->balance_owed($event_id);
$this->session->set_flashdata('flashmessage', 'A Balance has been defined as owed for Event #' . $event_id);
}
else
$this->session->set_flashdata('flashmessage', 'There was an error processing your request...');
header('Location: ' . $go_to);
}
function sync_with_alist($event_version)
{
$this->load->model('system/venue_model', 'venue_model');
$this->load->model('alist/group_model', 'group_model');
$this->load->model('alist/subscriber_model', 'subscriber_model');
/**
* Sync Group
*/
$venue_data = $this->venue_model->get_record(
array(
'venue_id' => $event_version['event_venue']
)
);
$group_exists = $this->group_model->exists(
array(
'return_field' => 'group_id',
'check_field' => 'group_longname',
'check_value' => $venue_data->venue_name
)
);
if (!$group_exists)
{
$this->group_model->add(
array(
'group_shortname' => $venue_data->venue_shortname,
'group_longname' => $venue_data->venue_name,
'group_status' => 1
)
);
$group_id = $this->db->insert_id();
}
else
$group_id = $this->group_model->translate_name_to_id($venue_data->venue_shortname);
/**
* Sync Subscriber
*/
$subscriber_exists = $this->subscriber_model->exists(
array(
'return_field' => 'subscriber_id',
'check_field' => 'subscriber_email',
'check_value' => $event_version['event_contact_email']
)
);
if (!$subscriber_exists)
{
$subscriber_name = explode(" ", $event_version['event_contact_name']);
$this->subscriber_model->add(
array(
'subscriber_firstname' => (string) $subscriber_name[0],
'subscriber_lastname' => (string) $subscriber_name[1],
'subscriber_email' => $event_version['event_contact_email'],
'subscriber_office_phone' => $event_version['event_contact_phone']
)
);
$subscriber_id = $this->db->insert_id();
}
else
{
$subscriber_data = $this->subscriber_model->find(
array(
'subscriber_email' => $event_version['event_contact_email']
)
);
$subscriber_id = $subscriber_data->subscriber_id;
}
$this->subscriber_model->set_quick_group($subscriber_id, $group_id);
}
}
<?php
/**
* Event Remote Controller
*
**/
class Remote extends Controller
{
var $default_error_message = 'The requested processing method is not available.';
var $json_data = array();
/**
* Class constructor
* @access public
* @param void
* @return void
* */
function Remote()
{
parent::Controller();
// Check if current user is logged in
$this->aa_auth->bouncer();
// Store user privileges in a local var (to use inside the controller)
$this->user_id = $this->session->userdata('user_id');
$this->user_acl = $this->aa_auth->refresh_auth(2);
$this->load->helper('url');
$this->load->helper('date');
$this->load->helper('text');
$this->load->model('user_model');
$this->load->model('misc_model');
$this->load->model('file_model');
$this->load->model('event/event_model', 'event_model');
$this->load->model('event/lead_model', 'lead_model');
$this->load->model('system/venue_model', 'venue_model');
$this->load->model('log_model', 'log_model');
if (($this->user_acl['superadmin'] === FALSE) || ($this->user_acl['admin'] === FALSE))
{
// Is not a superadmin or admin, means it is a manager or user,
// lets see if they have access to this app
if ($this->user_model->has_application($this->user_id, 'events') === FALSE)
{
$this->session->set_flashdata('flashmessage', 'You don\'t have access enabled to the event application.');
redirect('users/dashboard');
}
}
// Load the enabled venues
if (($this->user_acl['superadmin'] === FALSE) || ($this->user_acl['admin'] === FALSE))
{
$this->enabled_venues = $this->venue_model->get_venues_ddlist($this->user_id);
}
else
{
$this->enabled_venues = $this->venue_model->get_venues_ddlist();
}
$this->json_data['status'] = 'error';
$this->json_data['payload'] = array();
$this->json_data['message'] = 'Error processing your request, please try again later.';
}
/**
* Index
* @access public
* @param void
* @return void
* */
function index($params = NULL)
{
// Every AJAX call needs to have an ajax_method defined
if ($this->input->post('remote_method'))
{
// Retrieve the AJAX method name
$ajax_method = $this->input->post('remote_method', TRUE);
// and then we "rewrite" it for extra security
$ajax_method = '_' . str_replace('.', '_', $ajax_method);
$this->current_method = $ajax_method;
// and finally, we call a local method to handle the request
if (method_exists('Remote', $ajax_method))
$this->$ajax_method($params);
else
$this->_show_error($this->default_error_message);
}
else
$this->_show_error($this->default_error_message);
$this->_return_data();
}
function _show_error($error_message = NULL)
{
$this->json_data['status'] = 'error';
$this->json_data['payload'] = array();
$this->json_data['message'] = ($error_message == NULL) ? $this->default_error_message : $error_message;
}
function _return_data()
{
header('Content-Type: application/json');
echo json_encode($this->json_data);
}
function _menu_options_get($params = NULL)
{
if ($this->input->post('mm_venue'))
{
$this->load->model('event/lead_model');
$venue = split('-', $this->input->post('mm_venue'));
$options = $this->lead_model->get_menu_options($venue[0], $venue[1]);
$this->json_data['payload']['record_count'] = count($options);
$i = 0;
foreach ($options as $id => $value)
{
$this->json_data['payload']['menu_options'][$i] = array(
'id' => $value['id'],
'name' => $value['name'],
'order' => $value['order']
);
$i++;
}
$this->json_data['status'] = 'success';
$this->json_data['message'] = '';
}
else
$this->_show_error();
}
function _menu_option_save($params = NULL)
{
$this->load->model('event/lead_model');
$venue = split('-', $this->input->post('mm_venue'));
$menu['venue_id'] = $venue[0];
$menu['fo_name'] = $this->input->post('mm_name');
$menu['fo_description'] = '';
$menu['fo_order'] = $venue[1];
$menu['fo_order_food'] = $this->input->post('mm_order');
$this->lead_model->save_menu_option($menu);
$options = $this->lead_model->get_menu_options($venue[0], $venue[1]);
$this->json_data['payload']['record_count'] = count($options);
$i = 0;
foreach ($options as $id => $value)
{
$this->json_data['payload']['menu_options'][$i] = array(
'id' => $value['id'],
'name' => $value['name'],
'order' => $value['order']
);
$i++;
}
$this->json_data['selectHtml'] = $this->load->view(
'event/lead/menu_option_list', array('_options' => $this->lead_model->get_food_options()), TRUE
);
$this->json_data['status'] = 'success';
$this->json_data['message'] = '';
}
function _menu_option_delete($params = NULL)
{
$this->load->model('event/lead_model');
$menu = $this->lead_model->get_menu_option($this->input->post('id'));
$this->lead_model->delete_menu_option($this->input->post('id'));
$options = $this->lead_model->get_menu_options($menu->venue_id, $menu->fo_order);
$this->json_data['payload']['record_count'] = count($options);
$i = 0;
foreach ($options as $id => $value)
{
$this->json_data['payload']['menu_options'][$i] = array(
'id' => $value['id'],
'name' => $value['name'],
'order' => $value['order']
);
$i++;
}
$this->json_data['selectHtml'] = $this->load->view(
'event/lead/menu_option_list', array('_options' => $this->lead_model->get_food_options()), TRUE
);
$this->json_data['status'] = 'success';
$this->json_data['message'] = '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment