Last active
August 29, 2015 14:14
-
-
Save engram-design/8948a5cd9460323c2836 to your computer and use it in GitHub Desktop.
Fixes for MoreEvents ExpressionEngine plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Moreevents_ext { | |
var $name = 'moreEvents'; | |
var $version = '1.2.5'; | |
var $description = 'moreEvents system extensions'; | |
var $settings_exist = 'n'; | |
var $docs_url = ''; // 'http://expressionengine.com/user_guide/'; | |
var $table_name = "moreevents"; | |
var $settings = array(); | |
var $currency = array(); | |
/** | |
* Constructor | |
* | |
* @param mixed Settings array or empty string if none exist. | |
*/ | |
function __construct($settings = array()) | |
{ | |
$this->EE =& get_instance(); | |
$this->settings = $settings; | |
if($this->EE->input->get("D") != 'cp'){ //Only load if we are not in the CP | |
$this->EE->load->model("more_event_data"); | |
} | |
} | |
/** | |
* Incorporate the event data into the channel data | |
* | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function channel_entries_query_result($channel, $query_result) | |
{ | |
//Load the current currency | |
$this->EE->load->helper("currency"); | |
$this->currency = MoreEventCurrency::getActiveCurrency(); | |
//Fetch the event data | |
$q = $this->EE->db->get($this->table_name); | |
$events = array(); | |
foreach ($q->result_array() as $row) { | |
$events[$row['entry_id']] = $row; | |
$events[$row['entry_id']]['member_permissions'] = unserialize($events[$row['entry_id']]['member_permissions']); | |
} | |
//Preload the events so they are all cached. The loop below adds the price information, so we need this for performance | |
$this->EE->more_event_data->preload_events($q->result_array()); | |
//Add the event data to the channel data array | |
foreach($query_result as $key => $channel_entry){ | |
$is_event = FALSE; | |
$is_earlybird = FALSE; | |
if(isset($events[$channel_entry['entry_id']])){ | |
$is_event = TRUE; | |
$event = $events[$channel_entry['entry_id']]; | |
} | |
if($is_event){ | |
$is_earlybird = $this->EE->more_event_data->is_earlybird($event['id']) ? "y" : "n"; | |
} | |
if($is_earlybird) { | |
$is_earlybird = "y"; | |
} else { | |
$is_earlybird = "n"; | |
} | |
$query_result[$key]['event:id'] = $is_event ? $event['id'] : NULL; | |
$query_result[$key]['event:status'] = $is_event ? $event['status'] : NULL; | |
$query_result[$key]['event:registration_expiry'] = $is_event ? $event['registration_expiry'] : NULL; | |
$query_result[$key]['event:tickets_remaining'] = $is_event ? $event['tickets_available'] : NULL; | |
$query_result[$key]['event:notify_email'] = $is_event ? $event['notify_email'] : NULL; | |
$query_result[$key]['event:can_purchase'] = $is_event ? $this->EE->more_event_data->canPurchase($event) : "n"; | |
$query_result[$key]['event:is_earlybird'] = $is_event ? $is_earlybird : "n"; | |
$query_result[$key]['event:price'] = $is_event ? number_format($this->EE->more_event_data->logged_in_user_event_price($event['id']), 2) : NULL; //This requires a DB, so we preload the events using the preload events method (see above) | |
$query_result[$key]['event:full_price'] = $is_event ? number_format($this->EE->more_event_data->logged_in_user_event_price($event['id'], false), 2) : NULL; | |
$query_result[$key]["event:currency"] = $is_event ? $this->currency['htmlEntity'] : NULL; | |
$query_result[$key]["event:currency_code"] = $is_event ? $this->currency['code'] : NULL ; | |
$query_result[$key]["event:currency_name"] = $is_event ? $this->currency['name'] : NULL ; | |
$query_result[$key]["event:currency_symbol"] = $is_event ? $this->currency['symbol'] : NULL ; | |
$query_result[$key]['event:notify_on_registration'] = $is_event ? $event['notify_on_registration'] : NULL; | |
} | |
return $query_result; | |
} | |
/** | |
* Parses the registration exipry date | |
*/ | |
public function channel_entries_tagdata_end($tagdata="", $row, $channel) | |
{ | |
$tagdata = $this->EE->more_event_data->parseDates($tagdata, $row); | |
return $tagdata; | |
} | |
public function cartthrob_delete_from_cart_start() | |
{ | |
//Nothing for now | |
} | |
/** | |
* CartThrob Cart Updates | |
* | |
* We need to prevent people changing the ticket quantity for moreEvent items in the basket due to our registration requirements. | |
* We can also delete event TX records when moreevent items are deleted from the cart | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function cartthrob_update_cart_start() | |
{ | |
$this->EE->lang->loadfile('moreevents'); | |
$items = $this->EE->cartthrob->cart->items(); | |
$new_quantities = $this->EE->input->post("quantity") ? $this->EE->input->post("quantity") : array(); | |
$delete = $this->EE->input->post("delete") ? $this->EE->input->post("delete") : array(); | |
//Find the moreevent items that have changed in quantity | |
$changed_items = array(); | |
foreach($new_quantities as $key => $new_quantity){ | |
if(!isset($items[$key])) continue; | |
//Is this a morevent and different in quantity? | |
if($items[$key]->meta("moreevent_tx_id") && $items[$key]->quantity() != $new_quantity){ | |
$changed_items[$key] = $items[$key]; | |
} | |
} | |
//Is the current update changing a moreEvent booking? | |
if(count($changed_items) > 0){ | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("cartthrob_quantity_error")); | |
} | |
//Find the moreevent items that are being deleted | |
$deleted_items = array(); | |
foreach ($delete as $key => $value) { | |
if(!isset($items[$key])) continue; | |
//Is this a morevent? | |
if($items[$key]->meta("moreevent_tx_id")){ | |
$deleted_items[$key] = $items[$key]; | |
} | |
} | |
//If a moreevent is being deleted, we dont error but instead do some house cleaning by removing the event TX from the DB | |
foreach ($deleted_items as $key => $item) { | |
$this->EE->more_event_data->delete_event_tx($item->meta("moreevent_tx_id")); | |
} | |
} | |
public function cartthrob_on_authorize() | |
{ | |
$this->EE->load->model("more_event_data"); | |
//Fetch the entire order | |
$order = $this->EE->cartthrob->cart->order(); | |
//Cycle through the itens and find the items containing morevent meta information | |
foreach($order['items'] as $item){ | |
if(isset($item['meta']['moreevent_tx_id'])){ | |
$this->EE->more_event_data->process_payment_notification($item); | |
} | |
} | |
} | |
public function cartthrob_add_to_cart_start() | |
{ | |
$this->EE->lang->loadfile('moreevents'); | |
$entry_id = $this->EE->input->post("entry_id"); | |
if($this->EE->more_event_data->entry_is_event($entry_id)){ | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("cartthrob_add_error")); | |
} | |
} | |
function activate_extension() | |
{ | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'channel_entries_query_result', | |
'hook' => 'channel_entries_query_result', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'channel_entries_tagdata_end', | |
'hook' => 'channel_entries_tagdata_end', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_delete_from_cart_start', | |
'hook' => 'cartthrob_delete_from_cart_start', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_on_authorize', | |
'hook' => 'cartthrob_on_authorize', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_update_cart_start', | |
'hook' => 'cartthrob_update_cart_start', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
$data = array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_add_to_cart_start', | |
'hook' => 'cartthrob_add_to_cart_start', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
); | |
$this->EE->db->insert('extensions', $data); | |
} | |
function update_extension($current = '') | |
{ | |
if ($current == '' OR $current == $this->version) | |
{ | |
return FALSE; | |
} | |
if ($current < 1.2) | |
{ | |
$this->_upgrade_12(); | |
} | |
$this->EE->db->where('class', __CLASS__); | |
$this->EE->db->update('extensions',array('version' => $this->version)); | |
} | |
function disable_extension() | |
{ | |
$this->EE->db->where('class', __CLASS__); | |
$this->EE->db->delete('extensions'); | |
} | |
/** | |
* Inserts the cartthrob integration hooks | |
* | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
private function _upgrade_12() | |
{ | |
$hooks = array( | |
array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_delete_from_cart_start', | |
'hook' => 'cartthrob_delete_from_cart_start', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
), | |
array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_on_authorize', | |
'hook' => 'cartthrob_on_authorize', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
), | |
array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_update_cart_start', | |
'hook' => 'cartthrob_update_cart_start', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
), | |
array( | |
'class' => __CLASS__, | |
'method' => 'cartthrob_add_to_cart_start', | |
'hook' => 'cartthrob_add_to_cart_start', | |
'settings' => serialize($this->settings), | |
'priority' => 10, | |
'version' => $this->version, | |
'enabled' => 'y' | |
) | |
); | |
foreach ($hooks as $data) { | |
$this->EE->db->insert('extensions', $data); | |
} | |
} | |
} | |
// END CLASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Custom_fields_ft extends EE_Fieldtype { | |
var $db; | |
var $_output; | |
function __construct() | |
{ | |
parent::__construct(); | |
$this->EE =& get_instance(); | |
$this->db = $this->EE->db; | |
$this->EE->load->helper("form"); | |
} | |
/* | |
* Display the member price table | |
*/ | |
function display_field($data) | |
{ | |
$this->EE->lang->loadfile('moreevents'); | |
//Header | |
$this->_output('<table class="mainTable" id="moreevents__member_custom_fields_table" cellpadding="0" cellspacing="0"><thead><tr><th width="22%">'.$this->EE->lang->line('field_type').'</th><th width="40%">'.$this->EE->lang->line('field_custom_label').'</th><th> </th></tr><thead>'); | |
$this->_output("<tbody>"); | |
//Template | |
$this->_output("<tr id='moreevents_custom_field_row_template'>"); | |
$this->_output("<td>"); | |
$this->_output("<select class='moreevents_custom_field_type'><option value='textinput'>".$this->EE->lang->line('field_textinput')."</option><option value='textarea'>".$this->EE->lang->line('field_textarea')."</option></select>"); | |
$this->_output("</td>"); | |
$this->_output("<td>"); | |
$this->_output("<input type='text' class='moreevents_custom_field_label' />"); | |
$this->_output("</td>"); | |
$this->_output("<td>"); | |
$this->_output("<a href='#' class='moreevents_custom_field_delete'>".$this->EE->lang->line('field_delete')."</a>"); | |
$this->_output("</td>"); | |
$this->_output("</tr>"); | |
if(is_array($data) && count($data) > 0){ | |
$i = 0; | |
foreach ($data as $key => $d) { | |
$this->_output("<tr>"); | |
$this->_output("<td>"); | |
$this->_output(form_dropdown("moreevents__custom_fields[$i][type]", array("textinput" => $this->EE->lang->line('field_textinput'), "textarea" => $this->EE->lang->line('field_textarea')), $d['type'], 'class="moreevents_custom_field_type"')); | |
$this->_output("</td>"); | |
$this->_output("<td>"); | |
$this->_output("<input type='text' value='".$d['label']."' class='moreevents_custom_field_label' name='moreevents__custom_fields[$i][label]' />"); | |
$this->_output("</td>"); | |
$this->_output("<td>"); | |
$this->_output("<a href='#' class='moreevents_custom_field_delete'>".$this->EE->lang->line('field_delete')."</a>"); | |
$this->_output("</td>"); | |
$this->_output("</tr>"); | |
$i++; | |
} | |
} | |
$this->_output("</tbody>"); | |
//Footer | |
$this->_output("<tfoot>", "<tr>"); | |
$this->_output("<td colspan='3' id='moreevents__member_custom_fields_table_footer'>", "<a id='moreevents__member_custom_fields_add' href='#' class='submit'>".$this->EE->lang->line('field_addfield')."</a>" ,"</td>"); | |
$this->_output("</tr>" ,"</tfoot>"); | |
$this->_output("</table>"); | |
return $this->_output; | |
} | |
private function _fetch_member_groups() | |
{ | |
$this->db->select("group_id, group_title"); | |
$q = $this->db->get("member_groups"); | |
return $q->result_array(); | |
} | |
private function _output($str1='', $str2="", $str3="") | |
{ | |
$this->_output .= $str1.$str2.$str3; | |
} | |
function replace_tag($data, $params = array(), $tagdata = FALSE) | |
{ | |
} | |
// ============================================= | |
// = Process the address and return an address = | |
// ============================================= | |
/* | |
TODO Add marker position and config options for map | |
*/ | |
public function save($str) | |
{ | |
return $str; | |
} | |
} | |
// END Google_maps_ft class | |
/* End of file ft.google_maps.php */ | |
/* Location: ./system/expressionengine/third_party/google_maps/ft.google_maps.php */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Moreevents_mcp { | |
function __construct() | |
{ | |
$this->EE =& get_instance(); | |
$this->EE->load->model("more_event_cp_data"); | |
$this->EE->cp->load_package_css("global"); | |
} | |
public function index() | |
{ | |
//Page Title | |
//$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('moreevents_config_heading')); | |
$this->EE->view->cp_page_title = $this->EE->lang->line('moreevents_config_heading'); | |
//CSS | |
$this->EE->cp->load_package_css("moreevents_config"); | |
//Load the View | |
return $this->EE->load->view("overview", array(), TRUE); | |
} | |
public function gateway_settings() | |
{ | |
$this->EE->load->helper("currency"); | |
//$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('gateway_settings')); | |
$this->EE->view->cp_page_title = $this->EE->lang->line('gateway_settings'); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$this->EE->load->library("form_validation"); | |
$this->EE->cp->load_package_css("gateway"); | |
$this->EE->cp->add_js_script('ui', 'accordion'); | |
$this->EE->cp->load_package_js("gateway"); | |
$this->EE->form_validation->set_rules("settings[moreevents_sagepay_form_vendor_email]", "lang:sagepay_vendor_email", ""); | |
$this->EE->form_validation->set_rules("settings[moreevents_paypal_wps_vendor_email]", "lang:paypal_wps_vendor_email", ""); | |
$this->EE->form_validation->set_rules('settings[]', 'Settings', ''); | |
$this->EE->form_validation->set_rules('submit', 'Submit', 'required'); | |
$this->EE->form_validation->set_error_delimiters("", ""); | |
if ($this->EE->form_validation->run()) { | |
//Save | |
$this->EE->more_event_cp_data->save_settings(); | |
$this->EE->session->set_flashdata('message_success', $this->EE->lang->line('settings_updated')); | |
$this->EE->functions->redirect(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents"); | |
}else{ | |
$data['moreevents_sagepay_form_tx_type'] = $this->EE->config->item("moreevents_sagepay_form_tx_type"); | |
$data['moreevents_sagepay_form_vendor_email'] = $this->EE->config->item("moreevents_sagepay_form_vendor_email"); | |
$data['moreevents_sagepay_form_send_emails'] = $this->EE->config->item("moreevents_sagepay_form_send_emails"); | |
$data['moreevents_sagepay_form_mode'] = $this->EE->config->item("moreevents_sagepay_form_mode"); | |
$data['moreevents_sagepay_form_vendor_name'] = $this->EE->config->item("moreevents_sagepay_form_vendor_name"); | |
$data['moreevents_sagepay_form_encryption_password'] = $this->EE->config->item("moreevents_sagepay_form_encryption_password"); | |
$data['moreevents_selected_gateway'] = $this->EE->config->item("moreevents_selected_gateway"); | |
$data['moreevents_paypal_wps_mode'] = $this->EE->config->item("moreevents_paypal_wps_mode"); | |
$data['moreevents_paypal_wps_vendor_email'] = $this->EE->config->item("moreevents_paypal_wps_vendor_email"); | |
$data['currencies'] = MoreEventCurrency::getAll(); | |
$data['active_currency'] = $this->EE->config->item("moreevents_currency") ? $this->EE->config->item("moreevents_currency") : MoreEventCurrency::getDefault(); | |
$data['cartthrob_installed'] = $this->EE->more_event_cp_data->is_cartthrob_installed(); | |
return $this->EE->load->view("settings/gateways",$data, TRUE); | |
} | |
} | |
public function member_group_settings() | |
{ | |
//$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('event_member_groups')); | |
$this->EE->view->cp_page_title = $this->EE->lang->line('event_member_groups'); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$this->EE->load->library("form_validation"); | |
$this->EE->form_validation->set_rules('member_groups[]', 'Member Groups', ''); | |
$this->EE->form_validation->set_rules('submit', 'Submit', 'required'); | |
if ($this->EE->form_validation->run()) { | |
//Save | |
$this->EE->more_event_cp_data->save_member_group_selection(); | |
$this->EE->session->set_flashdata('message_success', $this->EE->lang->line('settings_updated')); | |
$this->EE->functions->redirect(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents"); | |
}else{ | |
$data['active_groups'] = $this->EE->more_event_cp_data->get_active_member_groups(); | |
$data['member_groups'] = $this->EE->more_event_cp_data->get_member_groups(); | |
return $this->EE->load->view("settings/member_groups",$data, TRUE); | |
} | |
} | |
public function channel_settings() | |
{ | |
//$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('event_channels')); | |
$this->EE->view->cp_page_title = $this->EE->lang->line('event_channels'); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$this->EE->load->library("form_validation"); | |
$this->EE->form_validation->set_rules('channels[]', 'Channel Settings', ''); | |
$this->EE->form_validation->set_rules('submit', 'Submit', 'required'); | |
if ($this->EE->form_validation->run()) { | |
//Save | |
$this->EE->more_event_cp_data->save_channel_selection(); | |
$this->EE->session->set_flashdata('message_success', $this->EE->lang->line('settings_updated')); | |
$this->EE->functions->redirect(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents"); | |
}else{ | |
$data['channels'] = $this->EE->more_event_cp_data->get_channels(); | |
return $this->EE->load->view("settings/channels",$data, TRUE); | |
} | |
} | |
public function event_list() | |
{ | |
//$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('events_and_attendees')); | |
$this->EE->view->cp_page_title = $this->EE->lang->line('events_and_attendees'); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$data['events'] = $this->EE->more_event_cp_data->get_events(); | |
return $this->EE->load->view("event_list", $data, TRUE); | |
} | |
public function transaction_list() | |
{ | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$data['transactions'] = $this->EE->more_event_cp_data->get_transactions(); | |
$this->EE->load->library('pagination'); | |
$config['base_url'] = BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=transaction_list"; | |
$config['total_rows'] = count($data['transactions']); | |
$config['page_query_string'] = TRUE; | |
$config['per_page'] = 1; | |
$config['num_links'] = 10; | |
$config['next_link'] = lang("next"); | |
$config['prev_link'] = lang("previous"); | |
$config['first_link'] = lang("first"); | |
$config['last_link'] = lang("last"); | |
$this->EE->pagination->initialize($config); | |
$offset = $this->EE->input->get("per_page") ? $this->EE->input->get("per_page") : 0; | |
//$data['transactions'] = array_slice($data['transactions'], $offset, $config['per_page']); | |
//$this->EE->cp->set_variable('cp_page_title', $this->EE->lang->line('event_transactions')); | |
$this->EE->view->cp_page_title = $this->EE->lang->line('event_transactions'); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
return $this->EE->load->view("transaction_list", $data, TRUE); | |
} | |
public function view_event() | |
{ | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=event_list", $this->EE->lang->line('events_and_attendees')); | |
$this->EE->cp->load_package_css("moreevents_management"); | |
$data['event_id'] = $this->EE->input->get("event_id"); | |
if(!$data['event_id']) show_error("Event not specified"); | |
$data['event'] = $this->EE->more_event_cp_data->get_event($data['event_id']); | |
$data['attendees'] = $this->EE->more_event_cp_data->get_event_attendees($data['event_id']); | |
$this->EE->load->library('pagination'); | |
$config['base_url'] = BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=view_event".AMP."event_id=".$data['event_id']; | |
$config['total_rows'] = count($data['attendees']); | |
$config['page_query_string'] = TRUE; | |
$config['per_page'] = 20; | |
$config['num_links'] = 10; | |
$config['next_link'] = lang("next"); | |
$config['prev_link'] = lang("previous"); | |
$config['first_link'] = lang("first"); | |
$config['last_link'] = lang("last"); | |
$this->EE->pagination->initialize($config); | |
$offset = $this->EE->input->get("per_page") ? $this->EE->input->get("per_page") : 0; | |
//$data['attendees'] = array_slice($data['attendees'], $offset, $config['per_page']); | |
//$this->EE->cp->set_variable('cp_page_title', $data['event']['title']); | |
$this->EE->view->cp_page_title = $data['event']['title']; | |
return $this->EE->load->view("view_event", $data, TRUE); | |
} | |
public function view_transaction() | |
{ | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents", $this->EE->lang->line('moreevents_module_name')); | |
$this->EE->cp->set_breadcrumb(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=transaction_list", $this->EE->lang->line('event_transactions')); | |
$this->EE->cp->load_package_css("moreevents_management"); | |
$event_tx_id = $this->EE->input->get("transaction_id"); | |
if(!$event_tx_id) show_error(lang("transaction_not_specified")); | |
//$this->EE->cp->set_variable('cp_page_title', lang("event_view_transactions")); | |
$this->EE->view->cp_page_title = lang("event_view_transactions"); | |
$data['transaction'] = $this->EE->more_event_cp_data->get_event_tx($event_tx_id); | |
$data['event'] = $this->EE->more_event_cp_data->get_event($data['transaction']['event_id']); | |
return $this->EE->load->view("view_transaction", $data, TRUE); | |
} | |
public function export_transactions() | |
{ | |
$this->EE->load->helper("download"); | |
$transaction_type = $this->EE->input->get("transaction_type"); | |
$name = "Event-transactions.csv"; | |
$data = $this->EE->more_event_cp_data->transaction_csv($transaction_type); | |
force_download($name, $data); | |
} | |
public function export_attendees() | |
{ | |
$this->EE->load->helper("download"); | |
$event_id = $this->EE->input->get("event_id"); | |
if(!$event_id) show_error("Event not specified"); | |
$name = "Event-attendees.csv"; | |
$data = $this->EE->more_event_cp_data->attendee_csv($event_id); | |
force_download($name, $data); | |
} | |
public function new_attendee() | |
{ | |
$this->EE->load->model("more_event_data"); | |
$this->EE->load->library("form_validation"); | |
//$this->EE->cp->set_variable('cp_page_title', "Register new attendee"); | |
$this->EE->view->cp_page_title = "Register new attendee"; | |
$this->EE->form_validation->set_rules("attendees[0][name]", "Name", ""); | |
if($this->EE->form_validation->run()){ | |
$event_tx_id = $this->EE->input->get("event_tx_id"); | |
if(!$event_tx_id) | |
show_error("Event transaction not found"); | |
//Get the event | |
$event_tx_data = $this->EE->more_event_data->get_event_purchase($event_tx_id); | |
if(!$event_tx_data ) | |
show_error("Invalid event transaction"); | |
//Data present? | |
$data['attendees'] = $this->EE->input->post("attendees"); | |
if(!$data['attendees']) | |
show_error("You must complete all attendee information before proceeding"); | |
//Names present? | |
$count = 0; | |
foreach($data['attendees'] as $attendee){ | |
if(!$attendee['name']) | |
show_error("You must provide a name for all attendees"); | |
$count++; | |
} | |
//Correct number of attendees? | |
if($count != $event_tx_data['quantity']) | |
show_error("Please provide details for all attendees"); | |
$this->EE->more_event_data->update_event_purchase_attendee_data($event_tx_id, $data); | |
$this->EE->more_event_cp_data->activate_manual_transaction($event_tx_id); | |
$this->EE->more_event_data->activate_event_tx_attendees($event_tx_id); | |
$this->EE->functions->redirect(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=view_event".AMP."event_id=".$event_tx_data['event_id']); | |
}else{ | |
$event_id = $this->EE->input->get("event_id"); | |
//Register a manual transaction | |
$data['tx_id'] = $this->EE->more_event_cp_data->new_manual_transaction($event_id); | |
$data['event'] = $this->EE->more_event_data->get_event($event_id); | |
$data['custom_fields'] = $this->EE->more_event_data->build_custom_field_html($data['tx_id']); | |
return $this->EE->load->view("new_attendee", $data, TRUE); | |
} | |
} | |
public function delete_attendee() | |
{ | |
$attendee_id = $this->EE->input->get("attendee_id"); | |
$event_id = $this->EE->input->get("event_id"); | |
if(!$attendee_id) | |
show_error("Attendee not specified"); | |
$this->EE->more_event_cp_data->delete_attendee($attendee_id, $event_id); | |
$this->EE->functions->redirect(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=view_event".AMP."event_id=".$event_id); | |
} | |
public function delete_transaction() | |
{ | |
$transaction_id = $this->EE->input->get("transaction_id"); | |
if(!$transaction_id) | |
show_error("Transaction ID not specified"); | |
$this->EE->more_event_cp_data->delete_transaction($transaction_id); | |
$this->EE->functions->redirect(BASE.AMP."C=addons_modules".AMP."M=show_module_cp".AMP."module=moreevents".AMP."method=transaction_list"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
class Moreevents { | |
var $events_table_name = "moreevents"; | |
public function __construct() | |
{ | |
$this->EE =& get_instance(); | |
$this->EE->load->model("more_event_data"); | |
$this->EE->lang->loadfile('moreevents'); | |
} | |
public function _process_payment_details() | |
{ | |
# code... | |
} | |
/** | |
* Entrance for successful payment gateway purchases | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function _process_payment_success() | |
{ | |
$data = $this->EE->more_event_data->process_incoming_gateway_data(); | |
//Valid transaction ID ? | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
if(!$event_tx ) | |
$this->EE->output->show_user_error('general', $this->EE->lang->line("invalid_tx_id")); | |
$this->EE->load->helper('string'); | |
if($event_tx['transaction_successful'] == "y"){ | |
//Send them to the success page | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($event_tx['success_template']."/".$data['id']))); | |
}else{ | |
//Send them to the error page | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($event_tx['fail_template']."/".$data['id']))); | |
} | |
} | |
public function _process_free_event() | |
{ | |
$data = $this->EE->more_event_data->free_gateway_data(); | |
//Valid transaction ID ? | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
if(!$event_tx ) | |
$this->EE->output->show_user_error('general', $this->EE->lang->line("invalid_tx_id")); | |
$this->EE->load->helper('string'); | |
//Send them to the success page | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($event_tx['success_template']."/".$data['id']))); | |
} | |
/** | |
* Entrance for failed payment gateway purchases | |
* THIS MIRRORS THE PAYMENT SUCCESS PAGE | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function _process_payment_error() | |
{ | |
$data = $this->EE->more_event_data->process_incoming_gateway_data(); | |
//Valid transaction ID ? | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
if(!$event_tx ) | |
$this->EE->output->show_user_error('general', $this->EE->lang->line("invalid_tx_id")); | |
$this->EE->load->helper('string'); | |
if($event_tx['transaction_successful'] == "y"){ | |
//Send them to the success page | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($event_tx['success_template']."/".$data['id']))); | |
}else{ | |
//Send them to the error page | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($event_tx['fail_template']."/".$data['id']))); | |
} | |
} | |
public function quantity_form() | |
{ | |
//Grab the entry ID by param or last segment | |
$event_id = $this->EE->TMPL->fetch_param('event_id'); | |
if(!$event_id) $event_id = $this->EE->uri->segment($this->EE->uri->total_segments()); | |
if(!$event_id) return; | |
//Grab the content between the tags | |
$template_data = $this->EE->TMPL->tagdata; | |
//Registration Page | |
$next_page = $this->EE->TMPL->fetch_param("continue"); | |
//Get the channel entry | |
$this->EE->db->where($this->events_table_name.".id", $event_id); | |
$this->EE->db->join("channel_titles", "channel_titles.entry_id = {$this->events_table_name}.entry_id"); | |
$entry = $this->EE->db->get($this->events_table_name)->row_array(); | |
if(!$entry) return ; | |
//Build an aray of tags available in the template | |
$data = array(); | |
$data[0] = array( | |
//Channel data | |
"entry_id" => $entry['entry_id'], | |
"site_id" => $entry['site_id'], | |
"channel_id" => $entry['channel_id'], | |
"author_id" => $entry['author_id'], | |
"title" => $entry['title'], | |
"url_title" => $entry['url_title'], | |
"status" => $entry['status'], | |
//Event data | |
"event:id" => $event_id, | |
"event:status" => $entry['status'], | |
"event:is_earlybird" => $this->EE->more_event_data->is_earlybird($event_id) ? "y" : "n", | |
"event:local_earlybird" => $this->EE->more_event_data->is_earlybird($event_id) ? "y" : "n", | |
"event:registration_expiry" => $entry['registration_expiry'], | |
/** | |
* TODO: Allow customized date usage with registration_expiry | |
*/ | |
"event:tickets_available" => $entry['tickets_available'], | |
"event:price" => number_format($this->EE->more_event_data->logged_in_user_event_price($event_id), 2), | |
"event:full_price" => number_format($this->EE->more_event_data->logged_in_user_event_price($event_id, FALSE), 2), | |
"event:can_purchase" => $this->EE->more_event_data->canPurchase($entry), | |
"event:currency" => $this->EE->more_event_data->currency['htmlEntity'], | |
"event:currency_code" => $this->EE->more_event_data->currency['code'], | |
"event:currency_name" => $this->EE->more_event_data->currency['name'], | |
"event:currency_symbol" => $this->EE->more_event_data->currency['symbol'] | |
); | |
//If the earlybird and the normal price are the same, switch the earlybird flag off | |
if($data[0]['event:price'] == $data[0]['event:full_price']){ | |
$data[0]['event:earlybird'] = 'n'; | |
} | |
//Parse | |
$template_data = $this->EE->TMPL->parse_variables($template_data, $data); | |
//Add the form wrapper | |
$form_details = array( | |
"action" => $this->EE->functions->fetch_site_index(0,0), | |
'name' => 'quantity', | |
'id' => $this->EE->TMPL->form_id, | |
'class' => $this->EE->TMPL->form_class, | |
'hidden_fields' => array( | |
"ACT" => $this->EE->functions->fetch_action_id("Moreevents", "_process_quantity_form"), | |
"NXT" => $next_page, | |
"EVID" => $event_id | |
), | |
'secure' => TRUE | |
); | |
$template_data = $this->EE->functions->form_declaration($form_details).$template_data."</form>"; | |
return $template_data; | |
} | |
/** | |
* Processes the users quantity selection, sets up the event_tx and redirects to registration | |
* | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function _process_quantity_form() | |
{ | |
//Make sure everything is present | |
$data['event_id'] = $this->EE->input->post("EVID"); | |
$next_page = $this->EE->input->post("NXT"); | |
$data['quantity'] = $this->EE->input->post("quantity"); | |
$event_tx_id = $this->EE->more_event_data->new_event_purchase($data); | |
$this->EE->load->helper('string'); | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($next_page ."/".$event_tx_id))); | |
} | |
/** | |
* Presents a form to enter attendee details | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function registration_form() | |
{ | |
//Grab the entry ID by param or last segment | |
$event_tx_id = $this->EE->TMPL->fetch_param('event_tx_id'); | |
if(!$event_tx_id) $event_tx_id = $this->EE->uri->segment($this->EE->uri->total_segments()); | |
if(!$event_tx_id) return; | |
//Billing page | |
$next_page = $this->EE->TMPL->fetch_param("continue"); | |
//Grab the content between the tags | |
$template_data = $this->EE->TMPL->tagdata; | |
//Add the form wrapper | |
$form_details = array( | |
"action" => $this->EE->functions->fetch_site_index(0,0), | |
'name' => 'registration', | |
'id' => $this->EE->TMPL->form_id, | |
'class' => $this->EE->TMPL->form_class, | |
'hidden_fields' => array( | |
"ACT" => $this->EE->functions->fetch_action_id("Moreevents", "_process_registration_form"), | |
"NXT" => $next_page, | |
"EVTXID" => $event_tx_id | |
), | |
'secure' => TRUE | |
); | |
$template_data = $this->EE->functions->form_declaration($form_details).$template_data."</form>"; | |
return $template_data; | |
} | |
/** | |
* For use inside a Registration form, loops over attendee details | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function attendee_details() | |
{ | |
//Grab the entry ID by param or last segment | |
$event_tx_id = $this->EE->TMPL->fetch_param('event_tx_id'); | |
if(!$event_tx_id) $event_tx_id = $this->EE->uri->segment($this->EE->uri->total_segments()); | |
$url_title = $this->EE->TMPL->fetch_param('url_title'); | |
$entry_id = (integer) $this->EE->TMPL->fetch_param('entry_id'); | |
$event_id = $this->EE->TMPL->fetch_param('event_id'); | |
if(!$event_tx_id && !$url_title && !$entry_id && !$event_id) return; | |
//Billing page | |
$next_page = $this->EE->TMPL->fetch_param("continue"); | |
//Grab the content between the tags | |
$template_data = $this->EE->TMPL->tagdata; | |
$attendees = array(); | |
//Get the event | |
$event_tx_data = $this->EE->more_event_data->get_event_purchase($event_tx_id); | |
$attendees = $event_tx_data['attendees']; | |
//If url_title is specified then we are displaying a list of attendees for an event | |
if($url_title){ | |
$attendees = $this->EE->more_event_data->get_entry_attendees($url_title); | |
} | |
//If entry_id is specified then we are displaying a list of attendees for an event | |
if($entry_id){ | |
$attendees = $this->EE->more_event_data->get_entry_attendees($entry_id); | |
} | |
//If entry_id is specified then we are displaying a list of attendees for an event | |
if($event_id){ | |
$attendees = $this->EE->more_event_data->get_event_attendees($event_id); | |
} | |
if(!$attendees) return; | |
//Setup the loop vars | |
$vars = array(); | |
$i = 0; | |
foreach($attendees as $attendee){ | |
$vars[] = array( | |
"count" => $i+1, | |
"zero_count" => $i, | |
"attendee_name_fieldname" => "attendees[$i][name]", | |
"name" => isset($attendee['name']) ? $attendee['name'] : NULL, | |
"custom_form_fields" => $this->EE->more_event_data->build_custom_field_html($event_tx_id, $i) | |
); | |
$i++; | |
} | |
$template_data = $this->EE->TMPL->parse_variables($template_data, $vars); | |
return $template_data; | |
} | |
/** | |
* Processes the submitted attendee details | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function _process_registration_form() | |
{ | |
//Make sure everything is present | |
$event_tx_id = $this->EE->input->post("EVTXID"); | |
if(!$event_tx_id) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("event_tx_id_not_found")); | |
//Get the event | |
$event_tx_data = $this->EE->more_event_data->get_event_purchase($event_tx_id); | |
if(!$event_tx_data ) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("invalid_tx_id")); | |
//Data present? | |
$data['attendees'] = $this->EE->input->post("attendees"); | |
if(!$data['attendees']) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("attendee_details_missing")); | |
//Names present? | |
$count = 0; | |
foreach($data['attendees'] as $attendee){ | |
if(!$attendee['name']) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("attendee_name_missing")); | |
$count++; | |
} | |
//Correct number of attendees? | |
if($count != $event_tx_data['quantity']) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("attendee_details_missing")); | |
$next_page = $this->EE->input->post("NXT"); | |
$this->EE->more_event_data->update_event_purchase_attendee_data($event_tx_id, $data); | |
/** | |
* CartThrob exception. If gateway is set to cartthrob we need to insert the current event transaction into the CT cart | |
*/ | |
if($this->EE->config->item("moreevents_selected_gateway") === "cartthrob_interface"){ | |
$this->EE->more_event_data->add_event_tx_to_cartthrob_cart($event_tx_id); | |
} | |
$this->EE->load->helper('string'); | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($next_page ."/".$event_tx_id))); | |
} | |
/** | |
* Displays the event registration page | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function billing_form() | |
{ | |
$this->EE->load->helper('country'); | |
//Grab the entry ID by param or last segment | |
$event_tx_id = $this->EE->TMPL->fetch_param('event_tx_id'); | |
if(!$event_tx_id) $event_tx_id = $this->EE->uri->segment($this->EE->uri->total_segments()); | |
if(!$event_tx_id) return; | |
//Valid event tx id? | |
if(!$this->EE->more_event_data->get_event_purchase($event_tx_id)) | |
return; | |
//Confirmation page | |
$next_page = $this->EE->TMPL->fetch_param("continue"); | |
//Grab the content between the tags | |
$template_data = $this->EE->TMPL->tagdata; | |
//Country Select Tag | |
$template_data = $this->EE->TMPL->parse_variables($template_data, array(array("event:billing_country_tag"=> country_select()))); | |
//Add the form wrapper | |
$form_details = array( | |
"action" => $this->EE->functions->fetch_site_index(0,0), | |
'name' => 'registration', | |
'id' => $this->EE->TMPL->form_id, | |
'class' => $this->EE->TMPL->form_class, | |
'hidden_fields' => array( | |
"ACT" => $this->EE->functions->fetch_action_id("Moreevents", "_process_billing_form"), | |
"EVTXID" => $event_tx_id, | |
"NXT" => $next_page | |
), | |
'secure' => TRUE | |
); | |
$template_data = $this->EE->functions->form_declaration($form_details).$template_data."</form>"; | |
return $template_data; | |
} | |
/** | |
* Processes the submitted billing data | |
* | |
* @param void | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function _process_billing_form() | |
{ | |
//Make sure everything is present | |
$event_tx_id = $this->EE->input->post("EVTXID"); | |
if(!$event_tx_id) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("event_tx_id_not_found")); | |
//Valid event tx id? | |
if(!$this->EE->more_event_data->get_event_purchase($event_tx_id)) | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("invalid_tx_id")); | |
$next_page = $this->EE->input->post("NXT"); | |
//All fields present? | |
$data = array(); | |
$data['billing_firstname'] = $this->EE->input->post("billing_firstname"); | |
$data['billing_lastname'] = $this->EE->input->post("billing_lastname"); | |
$data['billing_email'] = $this->EE->input->post("billing_email"); | |
$data['billing_address1'] = $this->EE->input->post("billing_address1"); | |
$data['billing_address2'] = $this->EE->input->post("billing_address2") ? $this->EE->input->post("billing_address2") : ""; | |
$data['billing_city'] = $this->EE->input->post("billing_city"); | |
$data['billing_postcode'] = $this->EE->input->post("billing_postcode"); | |
$data['billing_country'] = $this->EE->input->post("billing_country"); | |
//Show error if data is missing | |
if(!$data['billing_firstname'] || !$data['billing_lastname'] || !$data['billing_email'] || !$data['billing_address1'] || !$data['billing_city'] || !$data['billing_postcode'] || !$data['billing_country']){ | |
$this->EE->output->show_user_error('submission', $this->EE->lang->line("billing_details_missing")); | |
} | |
$this->EE->more_event_data->update_event_purchase_billing($event_tx_id, $data); | |
$this->EE->load->helper('string'); | |
$this->EE->functions->redirect($this->EE->functions->create_url(reduce_double_slashes($next_page ."/".$event_tx_id))); | |
} | |
public function confirmation_form() | |
{ | |
//Grab the entry ID by param or last segment | |
$event_tx_id = $this->EE->TMPL->fetch_param('event_tx_id'); | |
if(!$event_tx_id) $event_tx_id = $this->EE->uri->segment($this->EE->uri->total_segments()); | |
if(!$event_tx_id) return; | |
//Valid event tx id? | |
if(!$event_tx_data = $this->EE->more_event_data->get_event_purchase($event_tx_id)) | |
return; | |
//Confirmation page | |
$success_page = $this->EE->TMPL->fetch_param("success"); | |
$error_page = $this->EE->TMPL->fetch_param("error"); | |
if(!$error_page) $error_page = $success_page; | |
if(!$error_page || !$success_page) $this->EE->output->show_user_error('general', "Success template not specified"); | |
$this->EE->more_event_data->save_event_payment_return_paths($event_tx_id, $success_page, $error_page); | |
//Grab the content between the tags | |
$template_data = $this->EE->TMPL->tagdata; | |
//Combine all our event data for template variables | |
$vars = $this->EE->more_event_data->get_event_tx_vars($event_tx_id, $event_tx_data); | |
$template_data = $this->EE->TMPL->parse_variables($template_data, array($vars)); | |
//Add the payment gateway form | |
$template_data = $this->EE->more_event_data->build_payment_gateway($vars, $template_data); | |
return $template_data; | |
} | |
public function transaction() | |
{ | |
//Grab the entry ID by param or last segment | |
$event_tx_id = $this->EE->TMPL->fetch_param('event_tx_id'); | |
if(!$event_tx_id) $event_tx_id = $this->EE->uri->segment($this->EE->uri->total_segments()); | |
//Event id? | |
$event_id = $this->EE->TMPL->fetch_param('event_id'); | |
$member_id = $this->EE->TMPL->fetch_param('member_id'); | |
$order = $this->EE->TMPL->fetch_param('orderby'); | |
$sort = $this->EE->TMPL->fetch_param('sort'); | |
$transactions = array(); | |
$vars = array(); | |
//Fetch all transactions for an event OR for a specified member | |
if($event_id !== FALSE || $member_id !== FALSE){ | |
//We are showing a list of transactions | |
$transactions = $this->EE->more_event_data->get_event_transactions($event_id, $member_id, $order, $sort); | |
foreach ($transactions as $transaction) { | |
$vars[] = $this->EE->more_event_data->get_event_tx_vars($transaction['id']); | |
} | |
}else{ | |
//Most likely this is a checkout process and we show a single event transaction | |
$transactions[] = $this->EE->more_event_data->get_event_purchase($event_tx_id); | |
if($transactions[0]){ | |
$vars[] = $this->EE->more_event_data->get_event_tx_vars($event_tx_id, $transactions[0]); | |
} | |
} | |
if(!$vars) return; | |
//Grab the content between the tags | |
$template_data = $this->EE->TMPL->tagdata; | |
//Combine all our event data for template variables | |
$template_data = $this->EE->TMPL->parse_variables($template_data, $vars); | |
return $template_data; | |
} | |
/** | |
* Public Action for Payment Gateway Notifications (eg: PayPal IPN) | |
*/ | |
public function _gateway_notification() | |
{ | |
$data = $this->EE->more_event_data->process_payment_notification(); | |
//Valid transaction ID ? | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
if(!$event_tx ) | |
$this->EE->output->show_user_error('general', $this->EE->lang->line("invalid_tx_id")); | |
//Save the new payment details to the event TX record | |
$this->EE->more_event_data->update_event_tx_payment_status($data['id'], $data); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* More Event Module Data Model | |
*/ | |
class More_event_data extends CI_Model | |
{ | |
var $db; | |
var $EE; | |
var $garbageTimelimit = 86400; // One day | |
var $eventCache = array(); | |
var $gateway = "sagepay_form"; | |
var $currency = array(); | |
public function __construct() | |
{ | |
parent::__construct(); | |
$this->EE =& get_instance(); | |
$this->db =& $this->EE->db; //Shortened syntax for DB convenience | |
$this->EE->load->helper("currency"); | |
$this->currency = MoreEventCurrency::getActiveCurrency(); | |
$this->gateway = $this->EE->config->item("moreevents_selected_gateway"); | |
} | |
public function garbageCollection() | |
{ | |
$this->EE->db->where("raw_response IS NULL", NULL, FALSE); | |
$this->EE->db->where("last_activity <", time()-$this->garbageTimelimit); | |
$this->EE->db->delete("moreevents_tx"); | |
} | |
public function delete_event_tx($event_tx_id='') | |
{ | |
$this->EE->db->where("id", $event_tx_id); | |
$this->EE->db->delete("moreevents_tx"); | |
} | |
public function channel_is_event($channel_id='') | |
{ | |
$this->EE->db->where("channel_id", $channel_id); | |
$row = $this->EE->db->get("channels")->row(); | |
if(!$row) return FALSE; | |
if($row->moreevents_is_event == "y") return TRUE; | |
return FALSE; | |
} | |
public function entry_is_event($entry_id='') | |
{ | |
$this->EE->db->where("entry_id", $entry_id); | |
$this->EE->db->where("status", "y"); | |
$q = $this->EE->db->get("moreevents"); | |
if($q->num_rows() == 0) return FALSE; | |
return TRUE; | |
} | |
/** | |
* Determines whether an event ticket can be purchased. An array of the event data is supplied directly | |
*/ | |
public function canPurchase($eventArray='') | |
{ | |
if(!$eventArray){ | |
return "n"; | |
} | |
if($eventArray['status'] == "n"){ | |
return "n"; | |
} | |
if($eventArray['tickets_available'] == 0){ | |
return "n"; | |
} | |
if($eventArray['registration_expiry'] < $this->EE->localize->now){ | |
return "n"; | |
} | |
//GLOBAL: Member group allowed? | |
if(!in_array($this->EE->session->userdata('group_id'), explode("|", $this->EE->config->item("moreevents_allowed_member_groups")))) { | |
return "n"; | |
} | |
//EVENT: Member group allowed? | |
if(!isset($eventArray['member_permissions'][$this->EE->session->userdata('group_id')])){ | |
return "n"; | |
} | |
if($eventArray['member_permissions'][$this->EE->session->userdata('group_id')] == "y"){ | |
return "y"; | |
} | |
return "n"; | |
} | |
public function parseDates($tagdata='', $eventArray) | |
{ | |
//Parses the {event:registration_expiry format=''} tags | |
//Taken from Template.php. | |
if (strpos($tagdata, LD.'event:registration_expiry') !== FALSE && preg_match_all("/".LD."event\:registration_expiry\s+format=([\"\'])([^\\1]*?)\\1".RD."/", $tagdata, $matches)) | |
{ | |
for ($j = 0; $j < count($matches[0]); $j++) | |
{ | |
$tagdata = str_replace($matches[0][$j], $this->EE->localize->decode_date($matches[2][$j], $eventArray['event:registration_expiry']), $tagdata); | |
} | |
} | |
return $tagdata; | |
} | |
/** | |
* Saves the event data to the DB | |
* | |
* @param string $data | |
* @return void | |
* @author Christopher Imrie | |
*/ | |
public function save($params) | |
{ | |
//First check if this entry exists in the event table, if not create one | |
$event_id = $this->_get_event_id($params['entry_id']); | |
if($event_id === FALSE){ | |
$event_id = $this->_new_event($params['entry_id']); | |
} | |
$data = array( | |
"status" => $this->_yep_nope($params['mod_data']['status']), | |
"registration_expiry" => $params['mod_data']['registration_expiry'], | |
"notify_on_registration" => $this->_yep_nope($params['mod_data']['notify_on_registration']), | |
"notify_email" => $params['mod_data']['notify_email'], | |
"member_prices" => serialize($params['mod_data']['member_price'][0]), | |
"member_permissions" => serialize($params['mod_data']['member_price'][1]), | |
"member_earlybird_prices" => serialize($params['mod_data']['member_price'][2]), | |
"custom_fields" => serialize($params['mod_data']['custom_fields']), | |
"tickets_available" => $params['mod_data']['tickets_available'], | |
"earlybird_expiry" => $params['mod_data']['earlybird_expiry'] | |
); | |
$this->db->where("id", $event_id); | |
$this->db->update("moreevents", $data); | |
} | |
/** | |
* Sets up a new event_tx record in the DB | |
* | |
* @param array $data | |
* @return string | |
* @author Christopher Imrie | |
**/ | |
public function new_event_purchase($data=array()) | |
{ | |
if(!$data) return FALSE; | |
$this->EE->load->helper("event_title"); | |
//Ensure the quantity is a number | |
if(!is_numeric($data['quantity'])) | |
$this->EE->output->show_user_error("submission", $this->EE->lang->line("invalid_quantity")); | |
$data['id'] = $this->_generate_event_id($data['event_id']); | |
$data['last_activity'] = time(); | |
$data['member_id'] = $this->EE->session->userdata('member_id'); | |
$data['earlybird'] = $this->is_earlybird($data['event_id']) ? "y" : "n"; | |
$data['ticket_type'] = "standard"; | |
$data['currency'] = $this->currency['code']; | |
$data['ticket_title'] = event_title($data['event_id']); | |
if(isset($data['manual_transaction']) && $data['manual_transaction'] == "y"){ | |
$data['price'] = 0; | |
}else{ | |
$data['price'] = $this->logged_in_user_event_price($data['event_id']); | |
//Verify user is allowed. The price will be FALSE if the user is not allowed | |
if($data['price'] === FALSE){ | |
$this->EE->output->show_user_error("general", $this->EE->lang->line("user_registration_forbidden")); | |
return; | |
} | |
// Paypal Gateway reverses this function to allow us to specify the price per ticket | |
$data['price'] = $data['quantity'] * $data['price']; | |
} | |
$this->db->insert("moreevents_tx", $data); | |
//Save the id in a cookie for later | |
//$this->_save_event_id_with_user($data['id']); | |
return $data['id']; | |
} | |
/** | |
* Returns a specified event transaction | |
* | |
* @param string $event_tx_id The Event transaction ID | |
* @return array | |
* @author Christopher Imrie | |
**/ | |
public function get_event_purchase($event_tx_id='') | |
{ | |
$this->db->where("id", $event_tx_id); | |
$data = $this->db->get("moreevents_tx")->row_array(); | |
if(!$data) return; | |
if($data['attendees']){ | |
$data['attendees'] = unserialize($data['attendees']); | |
}else{ | |
// NO attendees yet, lets create an array with correct nubmer of items with a blank name | |
$data['attendees'] = array_fill(0, $data['quantity'], array("name" => "")); | |
} | |
if(isset($data['raw_response'])){ | |
$data['raw_response'] = unserialize($data['raw_response']); | |
} | |
$data['billing_name'] = $data['billing_firstname']." ".$data['billing_lastname']; | |
return $data; | |
} | |
/** | |
* Returns all attendees for a specified event ID | |
* | |
* @param string $event_id ID of the event | |
* @return array | |
* @author Christopher Imrie | |
**/ | |
public function get_event_attendees($event_id='') | |
{ | |
$this->EE->db->select("moreevents_attendees.*"); | |
$this->EE->db->where("moreevents.id", $event_id); | |
$this->EE->db->from("moreevents"); | |
$this->EE->db->join("moreevents_attendees", "moreevents.id = moreevents_attendees.event_id"); | |
$q = $this->EE->db->get()->result_array(); | |
foreach($q as $key => $value){ | |
$q[$key]['custom_fields'] = unserialize($q[$key]['custom_fields']); | |
} | |
return $q; | |
} | |
/** | |
* Returns all attendees for a specified channel entry | |
* | |
* @param integer|string $value Either the url_title or the entry_id of the channel entry | |
* @return array | |
* @author Christopher Imrie | |
**/ | |
public function get_entry_attendees($value='') | |
{ | |
if(is_string($value)){ | |
//URL title | |
$this->EE->db->where("channel_titles.url_title", $value); | |
}else{ | |
//Entry ID | |
$this->EE->db->where("channel_titles.entry_id", $value); | |
} | |
$this->EE->db->select("moreevents_attendees.*"); | |
$this->EE->db->from("channel_titles"); | |
$this->EE->db->join("moreevents", "channel_titles.entry_id = moreevents.entry_id"); | |
$this->EE->db->join("moreevents_attendees", "moreevents.id = moreevents_attendees.event_id"); | |
$q = $this->EE->db->get()->result_array(); | |
foreach($q as $key => $value){ | |
$q[$key]['custom_fields'] = unserialize($q[$key]['custom_fields']); | |
} | |
return $q; | |
} | |
/** | |
* Returns all transactions for a specified event ID or member ID | |
* | |
* @param string $event_id The ID of the event | |
* @param string $member_id The ID of a member to fetch/filter by | |
* @param string $order The DB column to use for ordering | |
* @param string $sort Result ordering (asc/desc) | |
* @return array | |
* @author Christopher Imrie | |
**/ | |
public function get_event_transactions($event_id=FALSE, $member_id = FALSE, $order = FALSE, $sort = FALSE) | |
{ | |
//Either event_id or member_id MUST be specified | |
if(!$event_id === FALSE && $member_id === FALSE) return array(); | |
if($event_id !== FALSE){ | |
$this->EE->db->where("event_id", $event_id); | |
} | |
if($member_id !== FALSE){ | |
$this->EE->db->where("member_id", $member_id); | |
} | |
$this->EE->db->where("transaction_successful", "y"); | |
$this->EE->db->where("raw_response IS NOT NULL", NULL, FALSE ); | |
if($order && $sort){ | |
$this->EE->db->order_by($order, $sort); | |
}else{ | |
$this->EE->db->order_by("last_activity","desc"); | |
} | |
$q = $this->EE->db->get("moreevents_tx")->result_array(); | |
foreach($q as $key => $row){ | |
if($q[$key]['attendees']){ | |
$q[$key]['attendees'] = unserialize($q[$key]['attendees']); | |
}else{ | |
// NO attendees yet, lets create an array with correct nubmer of items with a blank name | |
$q[$key]['attendees'] = array_fill(0, $q[$key]['quantity'], array("name" => "")); | |
} | |
$q[$key]['raw_response'] = unserialize($q[$key]['raw_response']); | |
$q[$key]['billing_name'] = $q[$key]['billing_firstname']." ".$q[$key]['billing_lastname']; | |
} | |
return $q; | |
} | |
/** | |
* Adds a specified event transaction ID to the CartThrob Cart | |
* | |
* @param string $event_tx_id The event transaction ID | |
* @param array $event_tx_id The event transaction array. If supplied this event transaction data will be used [optional] | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function add_event_tx_to_cartthrob_cart($event_tx_id='', $event_tx=array()) | |
{ | |
$this->EE->load->helper("event_title"); | |
//Get the transaction | |
if( ! $event_tx){ | |
$event_tx = $this->get_event_purchase($event_tx_id); | |
} | |
//Get the event | |
$event = $this->get_event($event_tx['event_id']); | |
//If we cant find either, then something has gone horribly wrong | |
if( ! $event_tx || ! $event) $this->EE->output->show_user_error('submission', $this->EE->lang->line("invalid_tx_id")); | |
//Load CartThrob | |
$this->EE->load->add_package_path(PATH_THIRD.'cartthrob/'); | |
$this->EE->load->library('cartthrob_loader'); | |
$params = array( | |
'title' => event_title($event_tx['event_id']), | |
'product_id' => $event['entry_id'], //your entry_id | |
'item_options' => array(), //ie, 'product_size' => 'L', | |
'quantity' => $event_tx['quantity'], | |
'class' => 'product', | |
'price' => round($event_tx['price']/$event_tx['quantity'], 2), //grab the price from your module tab based on member group and early bird dates | |
'no_shipping' => true, | |
); | |
foreach($event_tx['attendees'] as $key => $attendee){ | |
$params['item_options']["attendee_".($key+1)] = $attendee['name']; | |
} | |
$item = $this->EE->cartthrob->cart->add_item($params); | |
$item->set_meta('moreevent_tx_id', $event_tx_id); | |
//do this if you are in your own module action, as opposed to a cartthrob extension | |
$this->EE->cartthrob->cart->save(); | |
//Update the current event TX to be flagged as a carththrob order | |
$this->_update_event_purchase($event_tx_id, array("is_cartthrob" => "y", "cartthrob_channel_id" => $this->EE->cartthrob->store->config('orders_channel'))); | |
} | |
public function move_member_group($event_tx_id='', $event_tx) | |
{ | |
if(!$event_tx){ | |
$event_tx = $this->get_event_purchase($event_tx_id); | |
} | |
$member_group = 5; | |
$event_purchase_member_group = 9; | |
//TODO: needs to be controllable by CMS | |
$this->EE->db->where("member_id", $event_tx['member_id']); | |
$q = $this->EE->db->get("members")->row_array(); | |
if($q && ($q['group_id'] == $member_group || $q['group_id'] == $event_purchase_member_group)){ | |
$data = array( | |
"group_id" => $event_purchase_member_group, | |
"join_date" => time() //Update the join date since we need to limit this membership to a year | |
); | |
$this->EE->db->where("member_id", $event_tx['member_id']); | |
$this->EE->db->update("members", $data); | |
} | |
} | |
/** | |
* Updates the event purchase attendee information | |
* | |
* @param string $event_tx_id | |
* @param array $input_data | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function update_event_purchase_attendee_data($event_tx_id='', $input_data=array()) | |
{ | |
if(!isset($input_data['attendees'])) | |
return; | |
//Sort custom fields | |
$event_tx = $this->get_event_purchase($event_tx_id); | |
$event = $this->get_event($event_tx['event_id']); | |
if( ! $event['custom_fields']) { | |
$event['custom_fields'] = array(); | |
} | |
$data = array(); | |
foreach($input_data['attendees'] as $attendee){ | |
if(!isset($attendee['name'])) | |
show_error("Error processing attendee names"); | |
//Sort custom fields | |
$custom_fields = array(); | |
foreach($event['custom_fields'] as $key => $field){ | |
$custom_fields[] = array( | |
"label" => $field['label'], | |
"type" => $field['type'], | |
"value" => isset($attendee['custom_fields'][$key]) ? $attendee['custom_fields'][$key] : NULL | |
); | |
} | |
$data[] = array( | |
"name" => $attendee['name'], | |
"custom_fields" => $custom_fields | |
); | |
//TODO: Add support for custom fields | |
} | |
return $this->_update_event_purchase($event_tx_id, array("attendees" => $data)); | |
} | |
public function event_notifications($event_tx_id, $event_tx=FALSE) | |
{ | |
if(!$event_tx) { | |
$event_tx = $this->get_event_purchase($event_tx_id); | |
} | |
$event = $this->get_event($event_tx['event_id']); | |
$event_tx['priceEntity'] = MoreEventCurrency::getEntity($event_tx['currency']); | |
//Does this event require notifications? | |
if($event['notify_on_registration'] == "n" || !$event['notify_email']) return; | |
$this->EE->db->where("entry_id", $event['entry_id']); | |
$entry = $this->EE->db->get("channel_titles")->row_array(); | |
//No entry? Boo.. | |
if(!$entry) return; | |
$this->EE->load->library("email"); | |
$config['mailtype'] = "html"; | |
$this->EE->email->initialize($config); | |
//Buyer Notification | |
$this->EE->email->from($this->EE->config->item("webmaster_email"), $this->EE->config->item("webmaster_name")); | |
$this->EE->email->to($event_tx['billing_email']); | |
$this->EE->email->subject('Event Confirmation: '.$entry['title']); | |
$this->EE->email->message($this->EE->load->view("emails/buyer_notification", array("event_tx" => $event_tx, "entry" => $entry, "event" => $event), TRUE)); | |
$this->EE->email->send(); | |
//Webmaster Notification | |
$this->EE->email->from($this->EE->config->item("webmaster_email"), $this->EE->config->item("webmaster_name")); | |
$this->EE->email->to($event['notify_email']); | |
$this->EE->email->subject('Event Registration: '.$entry['title']); | |
$this->EE->email->message($this->EE->load->view("emails/admin_notification", array("event_tx" => $event_tx, "entry" => $entry, "event" => $event), TRUE)); | |
$this->EE->email->send(); | |
} | |
/** | |
* Saves the payment gateway status to the event TX record | |
* | |
* @param string $event_tx_id | |
* @param array $gateway_data | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function update_event_tx_payment_status($event_tx_id, $gateway_data) | |
{ | |
$data = array( | |
"transaction_successful" => $gateway_data['transaction_successful'], | |
"transaction_status" => $gateway_data['transaction_status'], | |
"transaction_id" => $gateway_data['transaction_id'], | |
"authorization_id" => $gateway_data['authorization_id'], | |
"amount_paid" => $gateway_data['amount_paid'], | |
"card_type" => $gateway_data['card_type'], | |
"last_four_digits" => $gateway_data['last_four_digits'], | |
"raw_response" => $gateway_data['raw_response'] | |
); | |
if(isset($gateway_data['is_cartthrob'])) { | |
$data['cartthrob_order_id'] = $gateway_data['cartthrob_order_id']; | |
$data['cartthrob_entry_title'] = $gateway_data['cartthrob_entry_title']; | |
} | |
$this->EE->db->where("id", $event_tx_id); | |
$this->EE->db->update("moreevents_tx", $data); | |
} | |
public function send_member_registration_details($event_tx_id='') | |
{ | |
$event_tx_data = $this->get_event_purchase($event_tx_id); | |
$data['member'] = $this->get_member($event_tx_data['member_id']); | |
$data['forgot_password'] = $this->EE->functions->create_url('site/forgotten-password'); | |
$data['login'] = $this->EE->functions->create_url('site/login'); | |
$data['event'] = $this->get_event_tx_vars($event_tx_id, $event_tx_data); | |
//Only send the email if the user has registered in the last 15 mins | |
if($data['member']['join_date'] < ($this->EE->localize->now - (15*60))) return; | |
if($data['member']['group_id'] == 9){ //New web members get special email | |
$message = $this->EE->load->view("web_member_registration_email", $data, TRUE); | |
}else{ | |
$message = $this->EE->load->view("normal_registration_email", $data, TRUE); | |
} | |
$this->load->library('email'); | |
$config['mailtype'] = "html"; | |
$this->EE->email->initialize($config); | |
$this->EE->email->from($this->EE->config->item("webmaster_email"), $this->EE->config->item("webmaster_name")); | |
$this->EE->email->to($data['member']['email']); | |
$this->email->subject("Member Registration Details"); | |
$this->email->message($message); | |
$this->email->send(); | |
} | |
public function get_member($member_id) | |
{ | |
$this->EE->db->where("member_id", $member_id); | |
$a = $this->EE->db->get("members")->row_array(); | |
return $a; | |
} | |
public function activate_event_tx_attendees($event_tx_id='', $event_tx=FALSE) | |
{ | |
if(!$event_tx){ | |
$event_tx = $this->get_event_purchase($event_tx_id); | |
} | |
if(count($event_tx['attendees']) == 0) return; | |
$event = $this->get_event($event_tx['event_id']); | |
//Event exists? | |
if(!$event) show_error("Unable to find the requested event"); | |
//Check we have enough slots available | |
if($event['tickets_available'] < count($event_tx['attendees'])) show_error("There are insufficient tickets available for this event to allocate them to your order."); | |
//Loop through the attendees, adding them to the attendee table | |
foreach($event_tx['attendees'] as $attendee){ | |
$data = array(); | |
$data['name'] = $attendee['name']; | |
$data['custom_fields'] = serialize($attendee['custom_fields']); | |
$data['event_id'] = $event_tx['event_id']; | |
$data['event_tx_id'] = $event_tx['id']; | |
$data['timestamp'] = time(); | |
$this->EE->db->insert("moreevents_attendees", $data); | |
} | |
//Reduce the total number of tickets left | |
$tickets_available = $event['tickets_available'] - count($event_tx['attendees']); | |
//Just incase | |
$tickets_available = $tickets_available < 0 ? 0 : $tickets_available; | |
$this->db->where("id", $event_tx['event_id']); | |
$this->EE->db->update("moreevents", array("tickets_available" => $tickets_available)); | |
} | |
/** | |
* Updates the event purchase TX billing data | |
* | |
* @param string $event_tx_id | |
* @param array $data | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function update_event_purchase_billing($event_tx_id='', $data) | |
{ | |
$a = array( | |
"billing_firstname" => $data['billing_firstname'], | |
"billing_lastname" => $data['billing_lastname'], | |
"billing_email" => $data['billing_email'], | |
"billing_address1" => $data['billing_address1'], | |
"billing_address2" => $data['billing_address2'], | |
"billing_city" => $data['billing_city'], | |
"billing_postcode" => $data['billing_postcode'], | |
"billing_country" => $data['billing_country'] | |
); | |
return $this->_update_event_purchase($event_tx_id, $a); | |
} | |
/** | |
* Gets a specified event as an array | |
* | |
* @param string $event_id | |
* @return array | |
* @author Christopher Imrie | |
**/ | |
public function get_event_tx_vars($event_tx_id='', $event_tx_data=FALSE) | |
{ | |
if(!$event_tx_data){ | |
$event_tx_data = $this->get_event_purchase($event_tx_id); | |
} | |
$this->EE->db->where("id", $event_tx_data['event_id']); | |
$event = $this->EE->db->get("moreevents")->row_array(); | |
$this->EE->db->where("entry_id", $event['entry_id']); | |
$data = $this->EE->db->get("channel_titles")->row_array(); | |
//We want the currency of this transaction, NOT the currency currently set | |
MoreEventCurrency::initWithCurrency($event_tx_data['currency']); | |
$currency = MoreEventCurrency::getActiveCurrency(); | |
//Add the event variables to the channel titles, prefixed with event: | |
$data['event:id'] = $event['id']; | |
$data['event:status'] = $event['status']; | |
$data['event:registration_expiry'] = $event['registration_expiry']; | |
$data['event:tickets_remaining'] = $event['tickets_available']; | |
$data['event:can_purchase'] = $this->canPurchase($event); | |
//Add the Event TX vars | |
$data['event:tx_id'] = $event_tx_data['id']; | |
$data['event:ticket_quantity'] = $event_tx_data['quantity']; | |
$data['event:price'] = number_format($event_tx_data['price'], 2); | |
$data['event:price_unformatted'] = $event_tx_data['price']; // UNDOCUMENTED | |
$data['event:is_free'] = $event_tx_data['price'] == 0 ? "y" : "n"; | |
$data['event:billing_name'] = $event_tx_data['billing_firstname']. " " . $event_tx_data['billing_lastname']; | |
$data['event:billing_firstname'] = $event_tx_data['billing_firstname']; | |
$data['event:billing_lastname'] = $event_tx_data['billing_lastname']; | |
$data['event:billing_email'] = $event_tx_data['billing_email']; | |
$data['event:billing_address1'] = $event_tx_data['billing_address1']; | |
$data['event:billing_address2'] = $event_tx_data['billing_address2']; | |
$data['event:billing_city'] = $event_tx_data['billing_city']; | |
$data['event:billing_postcode'] = $event_tx_data['billing_postcode']; | |
$data['event:billing_country'] = $event_tx_data['billing_country']; | |
$data['event:is_earlybird'] = $event_tx_data['earlybird']; | |
$data['event:ticket_type'] = $event_tx_data['ticket_type']; | |
//Currency | |
$data["event:currency"] = $currency['htmlEntity']; | |
$data["event:currency_code"] = $currency['code']; | |
$data["event:currency_name"] = $currency['name']; | |
$data["event:currency_symbol"] = $currency['symbol']; | |
$data['event:payment_attempt'] = $event_tx_data['payment_attempt']; | |
$data['event:transaction_successful'] = $event_tx_data['transaction_successful']; | |
$data['event:gateway_tx_status'] = $event_tx_data['transaction_status']; | |
$data['event:gateway_tx_id'] = str_replace(array("{", "}"), "", $event_tx_data['transaction_id']); | |
$data['event:authorization_id'] = $event_tx_data['authorization_id']; | |
$data['event:amount_paid'] = $event_tx_data['amount_paid']; | |
$data['event:card_type'] = $event_tx_data['card_type']; | |
$data['event:last_four_digits'] = $event_tx_data['last_four_digits']; | |
$data['event:raw_response'] = $event_tx_data['raw_response']; | |
return $data; | |
} | |
public function preload_events($event_array=array()) | |
{ | |
if( ! $event_array) { | |
$event_array = $this->EE->db->get("moreevents")->result_array(); | |
} | |
foreach($event_array as $row){ | |
$this->eventCache[$row['id']] = $row; | |
} | |
} | |
public function logged_in_user_event_price($event_id='', $allow_earlybird=TRUE, $local=FALSE) | |
{ | |
$group_id = $this->EE->session->userdata['group_id']; | |
$event = $this->get_event($event_id); | |
$earlybird = $this->is_earlybird($event_id, $event); | |
if($local){ | |
$price_type = "member_local_prices"; | |
}else{ | |
$price_type = "member_prices"; | |
} | |
//Earlybird? | |
if($earlybird && $allow_earlybird){ | |
//Local? | |
if($local){ | |
$price_type = "member_earlybird_local_prices"; | |
}else{ | |
$price_type = "member_earlybird_prices"; | |
} | |
} | |
//Check that the current member group exists is allowed | |
if(!isset($event[$price_type][$group_id]) || $event["member_permissions"][$group_id] != "y"){ | |
return FALSE; | |
} | |
//Get the price | |
$price = $event[$price_type][$group_id]; | |
//Failsafe in case the earlybird doesnt exist | |
if(!$price && $earlybird){ | |
$price = $event["member_prices"][$group_id]; | |
} | |
return $price; | |
} | |
public function is_earlybird($event_id='', $event_data=FALSE) | |
{ | |
if(!$event_data){ | |
$event_data = $this->get_event($event_id); | |
} | |
if($event_data['earlybird_expiry'] > $this->EE->localize->now){ | |
return TRUE; | |
} | |
return FALSE; | |
} | |
/** | |
* Returns a single event array | |
* | |
* @param string $event_id | |
* @return array | |
* @author Christopher Imrie | |
**/ | |
public function get_event($event_id='') | |
{ | |
if(isset($this->eventCache[$event_id])) { | |
$q = $this->eventCache[$event_id]; | |
} else { | |
$this->EE->db->where("id", $event_id); | |
$q = $this->EE->db->get("moreevents")->row_array(); | |
} | |
$q['member_prices'] = unserialize(@$q['member_prices']); | |
$q['member_permissions'] = unserialize(@$q['member_permissions']); | |
$q['custom_fields'] = unserialize(@$q['custom_fields']); | |
$q['member_earlybird_prices'] = unserialize(@$q['member_earlybird_prices']); | |
$q['member_local_prices'] = unserialize(@$q['member_local_prices']); | |
$q['member_earlybird_local_prices'] = unserialize(@$q['member_earlybird_local_prices']); | |
return $q; | |
} | |
public function build_custom_field_html($event_tx_id='', $attendee_id=0) | |
{ | |
$tx_data = $this->get_event_purchase($event_tx_id); | |
$event = $this->get_event($tx_data['event_id']); | |
$str = ""; | |
if(!is_array($event['custom_fields'])) $event['custom_fields'] = array(); | |
$field_count = 0; | |
foreach($event['custom_fields'] as $field){ | |
//Text input | |
if ($field['type'] == "textinput") { | |
$str .= "<div class='moreevents_custom_field moreevents_custom_field_textinput ctrlHolder'>"; | |
//Label | |
$str .= "<label >{$field['label']} <em>*</em></label>"; | |
$str .= "<input name='attendees[$attendee_id][custom_fields][$field_count]' class='textInput required' type='text'/><p class='formHint'></p>"; | |
//Text area | |
} else if ($field['type'] == "textarea") { | |
$str .= "<div class='moreevents_custom_field moreevents_custom_field_textarea ctrlHolder'>"; | |
//Label | |
$str .= "<label class='moreevents_custom_field_label moreevents_custom_field_label'>{$field['label']} <em>*</em></label>"; | |
$str .= "<textarea name='attendees[$attendee_id][custom_fields][$field_count]' class='required'></textarea><p class='formHint'></p>"; | |
} | |
$str .= "</div>"; | |
$field_count++; | |
} | |
return $str; | |
} | |
/** | |
* Selects the correct payment gateway, loads it and uses it to build the form | |
* | |
* @param array $vars | |
* @param array $template_data | |
* @return string | |
* @author Christopher Imrie | |
**/ | |
public function build_payment_gateway($vars, $template_data) | |
{ | |
if(!$this->gateway){ | |
$this->EE->output->show_user_error("general", lang("no_payment_gateway_selected")); | |
} | |
$this->EE->load->model("gateways/".$this->gateway, "event_payment_gateway"); | |
//Extra vars for the gateway that arent needed in the template: | |
$vars['successURL'] = $this->EE->functions->fetch_site_index(0,0)."?ACT=".$this->fetch_action_id("_process_payment_success"); | |
$vars['errorURL'] = $this->EE->functions->fetch_site_index(0,0)."?ACT=".$this->fetch_action_id("_process_payment_error"); | |
//Free event? | |
if($vars['event:price'] <= 0){ | |
return $this->build_free_event_form($vars, $template_data); | |
} | |
//Last minute check | |
if(!method_exists($this->EE->event_payment_gateway, "buildForm")){ | |
$this->EE->output->show_user_error("general", lang("error_initialising_gateway")); | |
} | |
return $this->EE->event_payment_gateway->buildForm($vars, $template_data); | |
} | |
/** | |
* Processes incoming payment gateway data and routes it to the correct payment module | |
*/ | |
public function process_incoming_gateway_data() | |
{ | |
if(!$this->gateway){ | |
$this->EE->output->show_user_error("general", lang("no_payment_gateway_selected")); | |
} | |
$this->EE->load->model("gateways/".$this->gateway, "event_payment_gateway"); | |
//Last minute check | |
if(!method_exists($this->EE->event_payment_gateway, "onGatewayReturn")){ | |
$this->EE->output->show_user_error("general", lang("error_initialising_gateway")); | |
} | |
//Let the Gateway do its thang... | |
$data = $this->EE->event_payment_gateway->onGatewayReturn(); | |
//Fetch the incomplete event transaction | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
//Save the new payment details to the event TX record | |
$this->update_event_tx_payment_status($data['id'], $data); | |
//Is the transaction successful, does the gateway want us to register this as complete now and is the transaction currently incomplete? | |
if($event_tx["transaction_successful"] == "n" && $data['transaction_successful'] == "y" && $this->EE->event_payment_gateway->registerComplete == "onGatewayReturn"){ | |
$this->register_transaction_successful($data); | |
} | |
return $data; | |
} | |
public function process_payment_notification($ct_item = FALSE) | |
{ | |
if(!$this->gateway){ | |
$this->EE->output->show_user_error("general", lang("no_payment_gateway_selected")); | |
} | |
$this->EE->load->model("gateways/".$this->gateway, "event_payment_gateway"); | |
//Last minute check | |
if(!method_exists($this->EE->event_payment_gateway, "onGatewayNotification")){ | |
$this->EE->output->show_user_error("general", lang("error_initialising_gateway")); | |
} | |
//If this method is being called by CartThrob, then we have the cart item as this methods arguments | |
if($ct_item){ | |
$ct = TRUE; | |
$data = $this->EE->event_payment_gateway->onGatewayNotification($ct_item); | |
}else{ | |
$ct = FALSE; | |
$data = $this->EE->event_payment_gateway->onGatewayNotification(); | |
} | |
//Fetch the incomplete event transaction | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
//Save the new payment details to the event TX record | |
$this->update_event_tx_payment_status($data['id'], $data); | |
//Is the transaction successful, does the gateway want us to register this as complete now and is the transaction currently incomplete? | |
if($event_tx["transaction_successful"] == "n" && $data['transaction_successful'] == "y" && $this->EE->event_payment_gateway->registerComplete == "onGatewayNotification"){ | |
$this->register_transaction_successful($data, !$ct); | |
} | |
return $data; | |
} | |
/** | |
* Activate event purchase | |
* | |
* Performs all the logic when a payment is successful. Eg: activating attendees, notifications | |
* | |
* @param string|array $data Either an array of event tx data or the id to an event tx | |
* @param boolean $notify Send notification emails (default TRUE) | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function register_transaction_successful($data, $notify = TRUE) | |
{ | |
//Fetch a fresh event transaction | |
if(is_array($data)){ | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data['id']); | |
}else{ | |
$event_tx = $this->EE->more_event_data->get_event_purchase($data); | |
} | |
//Process Attendees | |
$this->activate_event_tx_attendees($data['id'], $event_tx); | |
//Notify if needed | |
if($notify){ | |
$this->event_notifications($data['id'], $event_tx); | |
} | |
//Custom Extensions Hook | |
if ($this->EE->extensions->active_hook('moreevents_booking_success') === TRUE) | |
{ | |
$this->EE->extensions->call('moreevents_booking_success', $event_tx); | |
} | |
} | |
public function build_free_event_form($vars=array(), $template_data) | |
{ | |
//Add the form wrapper | |
$form_details = array( | |
"action" => $this->EE->functions->fetch_site_index(0,0), | |
'name' => 'confirmation_form', | |
'id' => $this->EE->TMPL->form_id, | |
'class' => $this->EE->TMPL->form_class, | |
'hidden_fields' => array( | |
"ACT" => $this->fetch_action_id("_process_free_event"), | |
"EVTXID" => $vars['event:tx_id'] | |
), | |
'secure' => TRUE | |
); | |
return $this->EE->functions->form_declaration($form_details).$template_data."</form>"; | |
} | |
public function free_gateway_data() | |
{ | |
//Normalise the response to allow compatibility with other payment gateways | |
$data = array(); | |
//Did the payment go through? | |
$data['transaction_successful'] = "y"; | |
//Description of the transaction status. This will contain errors if the payment didnt go through | |
$data['transaction_status'] = "Free event. No payment taken."; | |
//Extract the event ID | |
$data['id'] = $this->EE->input->post("EVTXID"); | |
//Extract the Sagepay transaction ID (if present) | |
$data['transaction_id'] = NULL; | |
//Extract the authorization ID (if present) | |
$data['authorization_id'] = NULL; | |
//Amount paid | |
$data['amount_paid'] = 0; | |
//Card information | |
$data['card_type'] = NULL; | |
$data['last_four_digits'] = NULL; | |
//Attach this for records | |
$data['raw_response'] = NULL; | |
//Save the new payment details to the event TX record | |
$this->update_event_tx_payment_status($data['id'], $data); | |
$this->register_transaction_successful($data); | |
return $data; | |
} | |
/** | |
* Saves the payment success/fail template string to the event TX record | |
* | |
* @param string $event_tx_id | |
* @param string $success | |
* @param string $fail | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
public function save_event_payment_return_paths($event_tx_id, $success='', $fail="") | |
{ | |
$this->_update_event_purchase($event_tx_id, array("success_template" => $success, "fail_template" => $fail)); | |
} | |
public function fetch_action_id($method_name='') | |
{ | |
// TODO: Add caching to this function for the lifecycle of a page to prevent multiple DB queries | |
$this->EE->db->where("class", "Moreevents"); | |
$this->EE->db->where("method", $method_name); | |
$q = $this->EE->db->get("actions")->row_array(); | |
if(!$q) return FALSE; | |
return $q['action_id']; | |
} | |
/** | |
* Updates an event TX id with a supplied array | |
* | |
* @param string $event_tx_id | |
* @param array $data | |
* @return void | |
* @author Christopher Imrie | |
**/ | |
private function _update_event_purchase($event_tx_id='', $data) | |
{ | |
//attendees needs to be a JSON array | |
if(isset($data['attendees']) && is_array($data['attendees'])){ | |
$data['attendees'] = serialize($data['attendees']); | |
} | |
//Update the timestamp | |
$data['last_activity'] = time(); | |
$this->db->where("id", $event_tx_id); | |
$this->db->update("moreevents_tx", $data); | |
} | |
public function increase_payment_attempt($event_tx_id) | |
{ | |
$this->EE->db->select("payment_attempt"); | |
$this->EE->db->where("id", $event_tx_id); | |
$d = $this->EE->db->get("moreevents_tx")->row_array(); | |
$d['payment_attempt'] = $d['payment_attempt']+1; | |
$this->_update_event_purchase($event_tx_id, $d); | |
} | |
public function publish_form_event_data($entry_id='') | |
{ | |
$this->db->where("entry_id", $entry_id); | |
$data = $this->db->get("moreevents")->row_array(); | |
if(!$data){ | |
$data = $this->_default_data(); | |
} | |
/* | |
* Unserialize | |
*/ | |
$data['member_prices'] = unserialize(@$data['member_prices']); | |
$data['custom_fields'] = unserialize(@$data['custom_fields']); | |
$data['member_permissions'] = unserialize(@$data['member_permissions']); | |
$data['member_earlybird_prices'] = unserialize(@$data['member_earlybird_prices']); | |
$data['member_local_prices'] = unserialize(@$data['member_local_prices']); | |
$data['member_earlybird_local_prices'] = unserialize(@$data['member_earlybird_local_prices']); | |
/* | |
* Combine prices and events, since this is how our custom fieldtype expects them | |
*/ | |
$data['prices'] = array(); | |
$data['prices'][0] = $data['member_prices']; | |
$data['prices'][1] = $data['member_permissions']; | |
$data['prices'][2] = $data['member_earlybird_prices']; | |
$data['prices'][3] = $data['member_earlybird_local_prices']; | |
$data['prices'][4] = $data['member_local_prices']; | |
return $data; | |
} | |
/** | |
* Attempts to fetch the event ID for a given entry ID | |
* | |
* @param string $entry_id | |
* @return mixed | |
* @author Christopher Imrie | |
*/ | |
private function _get_event_id($entry_id='') | |
{ | |
$this->db->where("entry_id", $entry_id); | |
$q = $this->db->get("moreevents"); | |
if($q->num_rows() > 0){ | |
return $q->row()->id; | |
} | |
return FALSE; | |
} | |
/** | |
* Creates a new row in the event table and returns the id | |
* | |
* @param string $entry_id | |
* @return void | |
* @author Christopher Imrie | |
*/ | |
private function _new_event($entry_id='') | |
{ | |
$data = array( | |
"id" => $this->_generate_event_id($entry_id), | |
"entry_id" => $entry_id | |
); | |
$this->db->insert("moreevents", $data); | |
return $data['id']; | |
} | |
/** | |
* Saves the supplied event tx ID to a cookie | |
* | |
* @param string $event_tx_id | |
* @return NULL | |
* @author | |
**/ | |
public function _save_event_id_with_user($event_tx_id='') | |
{ | |
$this->EE->input->set_cookie(array( | |
'name' => 'moreevents_tx', | |
'value' => $event_tx_id, | |
'secure' => TRUE | |
)); | |
} | |
/** | |
* Returns a 40 character long unique ID | |
* | |
* @param string $entry_id | |
* @return void | |
* @author Christopher Imrie | |
*/ | |
private function _generate_event_id($entry_id='') | |
{ | |
$str = $entry_id; // Unique to this entry | |
$str .= $this->EE->security->xss_hash(); // Random | |
$str .= $this->EE->config->item("site_label"); // Unique to this site | |
return sha1($str); | |
} | |
/** | |
* Sanitises a y/n select input and ensures we only get 'y' or 'n' | |
* | |
* @param string $str | |
* @return void | |
* @author Christopher Imrie | |
*/ | |
private function _yep_nope($str='') | |
{ | |
if($str === "y"){ | |
return "y"; | |
} | |
return "n"; | |
} | |
/** | |
* The default data to prepopulate the moreevents tab | |
* @return array | |
*/ | |
private function _default_data() | |
{ | |
return array( | |
"status" => "n", | |
"tickets_available" => "0", | |
"registration_expiry" => time() + 2592000, // + 30 days | |
"earlybird_expiry" => time()+5, | |
"notify_on_registration" => "n", | |
"notify_email" => "", | |
"member_price" => 0 | |
); | |
} | |
} |
Added issue with fieldtype indexing. The loop block on ft.custom_fields.php 52:70 and the incorrect syntax for form_dropdown()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested with ExpressionEngine 2.9.2. Note that
more_event_data.php
should be placed in themodels
subdirectory. Details on fixes described here - http://expressionengine.stackexchange.com/questions/18249/moreevents-not-saving-events-dev-log-error/28376#28376