File: //home/awaldron/public_html/archive/teampay/application/controllers/my_teams.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class My_teams extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
}
function index()
{
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
$data['teams'] = $this->teampay_model->get_teams( $data['user_id'] );
$data['page_title'] = "Active Teams";
$data['icon_title'] = "fa-group";
$data['navon'] = "my_teams";
$this->load->view('_header', $data);
$this->load->view('v_myteams', $data);
$this->load->view('_footer', $data);
}
function archive()
{
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
$data['teams'] = $this->teampay_model->get_teams( $data['user_id'], 0 );
$data['page_title'] = "Archived Teams";
$data['icon_title'] = "fa-clock-o";
$data['navon'] = "team_archive";
$this->load->view('_header', $data);
$this->load->view('v_myteams', $data);
$this->load->view('_footer', $data);
}
function team( $tid ) {
// Initialize page variables
$data = $this->tank_auth->auth_init();
$data['team'] = $this->teampay_model->get_team( $tid );
$data['carriers'] = $this->teampay_model->get_carriers();
$data['page_title'] = $data['team'][0]['team_name'];
$data['icon_title'] = "fa-group";
$data['navon'] = "my_teams";
$data['is_admin'] = ($data['is_logged_in'] && $data['user_id'] = $data['team'][0]['user_id']);
$this->load->view('_header', $data);
$this->load->view('v_team', $data);
$this->load->view('_footer', $data);
}
function update_team() {
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
$post = $this->input->post();
// get team record
$team = $this->teampay_model->get_team_record( $post['team_id'] );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Team Update Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to modify this team.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// validate data
$this->form_validation->set_rules('team_name', 'Team Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('sport_id', 'Sport', 'trim|required|xss_clean');
$this->form_validation->set_rules('team_fee', 'Team Fee', 'trim|required|xss_clean|is_numeric');
$this->form_validation->set_rules('team_fees_due', 'Team Fees Due', 'trim|required|xss_clean');
$post['team_fee'] = preg_replace("/[^0-9\.]/","", $post['team_fee']);
$post['team_fee'] = number_format( $post['team_fee'], 2 );
if ($this->form_validation->run()) { // validation ok
// send to model
$this->teampay_model->edit_team( $post );
$this->teampay_model->recalculate_player_fees( $post['team_id'] );
redirect('/my_teams');
} else {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Team Update Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('Oops, something went wrong with your player update. You probably didn\'t fill out a required field. Click the back button and give it another shot.');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
}
}
}
function add_player() {
// Initialize page variables
$data = $this->tank_auth->auth_init();
$post = $this->input->post();
// get team record
$team = $this->teampay_model->get_team_record( $post['team_id'] );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Player Update Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to modify this team.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// validate data
$this->form_validation->set_rules('player_fname', 'First Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('player_lname', 'Last Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('player_email', 'Email', 'trim|valid_email|xss_clean');
$post['player_text'] = preg_replace("/[^0-9]/","", $post['player_text']);
if ($this->form_validation->run()) { // validation ok
// send to model
$this->teampay_model->create_player( $post );
// re-calculate player fees
$this->teampay_model->recalculate_player_fees( $post['team_id'] );
redirect('/my_teams/team/'.$post['team_id']);
} else {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Add Player Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('Oops, something went wrong with your new player. You probably didn\'t fill out a required field. Click the back button and give it another shot.');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
}
}
}
function edit_player() {
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
$post = $this->input->post();
// get team record
$team = $this->teampay_model->get_team_record( $post['team_id'] );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Player Update Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to modify this team.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// validate data
$this->form_validation->set_rules('player_fname', 'First Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('player_lname', 'Last Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('player_email', 'Email', 'trim|valid_email|xss_clean');
$post['player_text'] = preg_replace("/[^0-9]/","", $post['player_text']);
if ($this->form_validation->run()) { // validation ok
// send to model
$this->teampay_model->edit_player( $post );
// re-calculate player fees
$this->teampay_model->recalculate_player_fees( $post['team_id'] );
redirect('/my_teams/team/'.$post['team_id']);
} else {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Player Update Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('Oops, something went wrong with your player update. You probably didn\'t fill out a required field. Click the back button and give it another shot.');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
}
}
}
function delplayer( $pid ) {
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
// get player record
$player = $this->teampay_model->get_player_record( $pid );
// get team record
$team = $this->teampay_model->get_team_record( $player['team_id'] );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Player Delete Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to delete this player.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// send to model
$this->teampay_model->delete_player( $pid );
// re-calculate player fees
$this->teampay_model->recalculate_player_fees( $team['team_id'] );
redirect('/my_teams/team/'.$team['team_id']);
}
}
function dupteam( $tid ) {
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
// get team record
$team = $this->teampay_model->get_team_record( $tid );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Team Duplication Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to duplicate this team.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// send to model
$new_tid = $this->teampay_model->duplicate_team( $tid, $team );
redirect('/my_teams');
}
}
function arcteam( $tid ) {
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
// get team record
$team = $this->teampay_model->get_team_record( $tid );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Team Archival Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to archive this team.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// send to model
$this->teampay_model->archive_team( $tid, 0 );
redirect('/my_teams');
}
}
function restoreteam( $tid ) {
// Initialize page variables
$data = $this->tank_auth->auth_init( true, '');
// get team record
$team = $this->teampay_model->get_team_record( $tid );
// make sure user has access to team
if ($team['user_id'] != $data['user_id']) {
$data['navon'] = 'my_teams';
$data['page_title'] = 'Team Restore Error';
$data['icon_title'] = 'fa-group';
$data['message'] = array('You do not have access to restore this team.', 'error');
$this->load->view('_header.php', $data);
$this->load->view('auth/general_message', $data);
$this->load->view('_footer.php', $data);
} else {
// send to model
$this->teampay_model->archive_team( $tid, 1 );
redirect('/my_teams');
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */