public function landing() { $this->load->model('users'); $this->load->model('players'); if ($this->users->is_loggedin()) { redirect('user'); } $page = $data['page'] = $this->pages->get('home'); $this->load->helper(array('form', 'url')); $data['theme'] = $this->config->item('theme'); $data['title'] = $page->title; $data['body'] = $page->body; $data['meta_description'] = $page->meta_description; $data['meta_keywords'] = $page->meta_keywords; $data['user'] = $this->users->get_by_id($this->users->id()); $is_mobile = $this->mdetect->DetectMobileLong(); $data['sport_data']=$sport_data=$this->config->item('sport_data'); $data['gambling_restricted_states'] = $this->options->get('gambling_resricted_states'); //get the current special games $this->db->where('pick5_special','A'); $this->db->where('status',0); $this->db->where('active',1); $this->db->where('first_game_cutoff >',time()); $this->db->order_by('first_game_cutoff','asc'); $this->db->limit(1); $speciala = $this->db->get('league')->row(); $this->db->where('pick5_special','B'); $this->db->where('status',0); $this->db->where('active',1); $this->db->where('first_game_cutoff >',time()); $this->db->order_by('first_game_cutoff','asc'); $this->db->limit(1); $specialb = $this->db->get('league')->row(); if(count($speciala) > 0 && count($specialb) > 0) { $data['extra_js'] = "<script type='text/javascript' src='".site_url('assets/fan-picks/js/pick5_front.js?v='.$this->config->item('ftd_version'))."'></script>"; $data['extra_js'] .= "<script type='text/javascript' src='".site_url('assets/common/js/jquery.payment.js?v='.$this->config->item('ftd_version'))."'></script>"; $data['league_info'] = $league_info = (array)$speciala; $data['league_info']['id'] = $league_info['cid']; $data['leagueb_info'] = $leagueb_info = (array)$specialb; $data['leagueb_info']['id'] = $leagueb_info['cid']; $data['game_found'] = 1; $data['states']=$this->misc->states_list(); $data['sport']=$sport=$league_info['sport']; $data['extra_js'] .= "<script type='text/javascript'> sport = '".$league_info['sport']."'; </script>"; $data['scoring']=$this->config->item('scoring'); $qcur = $this->db->query('SELECT season FROM ci_sport_event WHERE sport = "'.$sport.'" ORDER BY season DESC LIMIT 1'); $current = $qcur->row(); $current_season = $current->season; if($league_info['payout_type'] == 5) { $data['prize'] = $league_info['payout_other']; } else { $data['prize'] = '$'.round($league_info['total_prize'],2); } $event = implode('|',json_decode($league_info['included_events'])); $events = $this->leagues->get_league_events($event,$sport); $data['tiebreakers'] = array(); $fgd = json_decode($league_info['feat_game_data']); $included_ties = json_decode($fgd->included_ties); foreach($sport_data[$league_info['sport']]['pick5_tie_pos'] as $pos=>$val) { $temp = array(); $temp['name'] = $included_ties->$pos->player; $temp['event'] = $included_ties->$pos->event; $temp['label'] = $val['label']; $data['tiebreakers'][] = $temp; } $included_players = json_decode($fgd->included_players); $players = array(); foreach($included_players as $pos=>$p){ foreach($p as $key=>$val){ shuffle($val); foreach($val as $player) { $this_player = $this->players->get_player_by_id($player); foreach($events as $e){ if($sport != 'GOLF') { if($e->home_team_id==$this_player->team_id || $e->visiting_team_id==$this_player->team_id){ $pevent=$e; } } $event_data[$e->cid]=$e; } $temp=array(); $temp['fppg']=$this->players->get_season_fppg($this_player->cid,$sport,$current_season); $temp['player_id'] = $this_player->cid; $temp['player_name'] = $this_player->first_name.' '.$this_player->last_name; $temp['team_id'] = $this_player->team_id; $orig_photo = '/var/www/headshots/'.$this_player->team_id.'/'.$this_player->cid.'.jpg'; $thumb_photo = '/var/www/headshots/'.$this_player->team_id.'/'.$this_player->cid.'_100.jpg'; if(!file_exists($thumb_photo)) { if(file_exists($orig_photo)) { thumb_trans($orig_photo,'100'); $thumb = 'https://fan-picks.com/headshots/'.$this_player->team_id.'/'.$this_player->cid.'_100.jpg'; } else { $dir = dirname($orig_photo); $files = glob($dir . '/*'); $lcaseFilename = strtolower($orig_photo); foreach($files as $file) { if (strtolower($file) == $lcaseFilename) { thumb_trans($file,'100'); $thumb = 'https://fan-picks.com/headshots/'.$this_player->team_id.'/'.$this_player->cid.'_100.jpg'; } } if(!isset($thumb)) $thumb = 'assets/fan-picks/img/logo.png'; } $temp['thumb'] = $thumb; } else { $temp['thumb'] = 'https://fan-picks.com/headshots/'.$this_player->team_id.'/'.$this_player->cid.'_100.jpg'; } if(strtolower($sport)=='golf'){ $eventlabel=""; }else{ $eventlabel=($this_player->team_id==$pevent->home_team_id?$event_data[$pevent->cid]->away."@<strong>".$event_data[$pevent->cid]->home."</strong>":"<strong>".$event_data[$pevent->cid]->away."</strong>@".$event_data[$pevent->cid]->home); } $temp['event'] = $pevent->cid; $temp['eventlabel'] = $eventlabel; $players[$pos][$key][] = $temp; } } } $data['players'] = $players; } else { $data['game_found'] = 0; } $this->load->view($data['theme'].'/page-landing', $data); /* if($is_mobile == false) { } else { redirect('mobile/lobby'); } */ }
public function lobby_popup(){ $this->load->model("player_stats"); $this->load->helper('image_helper'); date_default_timezone_set('America/Detroit'); $league_id=$this->uri->segment(3); $data['theme'] = $this->options->get('theme'); $user_id = $this->users->id(); $returndata=array(); $data['league']=$league=$this->leagues->get_by_id($league_id); if(empty($league->included_events) || $league->included_events == "[]"){ echo json_encode( array("status" => "5")); die; } $data['sport_data']=$this->config->item("sport_data"); $data['prize_structure']=$this->leagues->get_prize_structure_by_id($league->prize_structure); $data['types'] = $this->config->item("league_types"); $data['entries'] = $this->leagues->get_teams_by_league($league_id); $data['ticket_types'] = $this->config->item('ticket_types'); $data['company_take']=$this->options->get('company_take'); if(!empty($data['league']->feat_game_data)){ $fgd=json_decode($data['league']->feat_game_data); if($fgd->custom_prize != false) { $prize=$fgd->custom_prize; $data['league']->prize = $prize; } else { if($data['league']->prize_structure == 7) { $prize=$data['league']->entry_fee; } else { $prize = $data['league']->size * $data['league']->entry_fee; } $rake=($fgd->custom_rake!==false)?(1-($fgd->custom_rake/100)):(1 - $data['company_take']); $data['league']->prize = $prize * $rake; } }else{ $data['league']->prize = $data['league']->total_prize; //quick hack for Top 3 rounding madness if($data['league']->prize_structure == 2) { $prize1 = number_format(($data['league']->size * $data['league']->entry_fee * (1 - $data['company_take']))*.444,2); $prize2 = number_format(($data['league']->size * $data['league']->entry_fee * (1 - $data['company_take']))*.333,2); $prize3 = number_format(($data['league']->size * $data['league']->entry_fee * (1 - $data['company_take']))*.222,2); $data['league']->prize = $prize1+$prize2+$prize3; } elseif($data['league']->prize_structure == 7) { $data['league']->prize = ($fgd->custom_prize!==false)?$fgd->custom_prize:$data['league']->entry_fee * (1-$data['company_take']); } else { $data['league']->prize = $data['league']->size * $data['league']->entry_fee * (1 - $data['company_take']); } } if(!empty($league->included_events)) $data['avail_games']=$this->leagues->get_avail_games_custom($league->included_events); else $data['avail_games']=$this->leagues->get_avail_games_by_time_slot($league->{'date'},$league->{'time'},$league->sport); //$data['avail_games']=$this->leagues->get_avail_games_by_time_slot($league->date,$league->time,$league->sport); if(isset($user_id)) { $this->db->where('user_id',$user_id); $this->db->where('league_id',$league->cid); $q=$this->db->get('league_team'); if($q->num_rows() > 0) $joined = 1; else $joined = 0; }else{ $joined = 0; } $returndata['id']=$league->cid; if($joined == 1) { if($league->first_game_cutoff>time()+(7*86400)){ $joinview = ''; }else{ $joinview = '<a href="'.site_url('view/live/'.$league->cid).'" class="btn btn-danger btn-small">'.vlang('lobby_league_view_long').'</a><br>' ; $help_text = 'Note: You can update and export your lineup by clicking View Matchup if time still permits.'; } } else { // old if below $league->first_game_cutoff>time()+(2*86400) if($league->early_reg != 0){ $joinview = '<button data-league-id="'.$league->cid.'" class="join_future btn btn-small btn-primary add_player join_view'.(!empty($league->password)?' password':'').'">'.vlang('lobby_league_join').'</button>'; }else{ if($league->type == 4) { $joinview = '<a href="'.site_url('game/over_under/'.$league->cid).'" data-league-id="'.$league->cid.'" class="btn btn-primary btn-small add_player join_view'.(!empty($league->password)?' password':'').'" id="'.$league->cid.'">'.vlang('lobby_league_join_ou').'</a>'; } else { $joinview = '<a href="'.site_url('league/player_select/'.$league->cid).'" data-league-id="'.$league->cid.'" class="btn btn-primary btn-small add_player join_view'.(!empty($league->password)?' password':'').'" id="'.$league->cid.'">'.vlang('lobby_league_join_long').'</a>'; } } } $returndata['joinview']=$joinview; $returndata['help_text']=$help_text; $returndata['entry_fee']='$'.$league->entry_fee; $returndata['first_game_cutoff_U']=date('U',$league->first_game_cutoff); $returndata['first_game_cutoff_A']['y']=date('Y',$league->first_game_cutoff); $returndata['first_game_cutoff_A']['m']=date('m',$league->first_game_cutoff); $returndata['first_game_cutoff_A']['d']=date('d',$league->first_game_cutoff); $returndata['first_game_cutoff_A']['h']=date('H',$league->first_game_cutoff); $returndata['first_game_cutoff_A']['i']=date('i',$league->first_game_cutoff); $returndata['first_game_cutoff_A']['s']=date('s',$league->first_game_cutoff); $returndata['first_game_cutoff']=date('D m/d/Y g:i a',$league->first_game_cutoff); if($league->feat==1){ //$returndata['speciality']='<i class="ftdi-featured"></i> '.vlang('league_speciality_featured'); $returndata['speciality']=''; }elseif($league->commissioner_id!=0){ $com=$this->users->get_by_id($league->commissioner_id); $returndata['speciality']='<i class="ftdi-usergen"></i> Created by: <a href="'.site_url('profile/show/'.$com->username).'" target="_blank">'.$com->username.'</a>'; } $returndata['payout']="<i class='".$data['prize_structure']->icon."'></i> ".vlang('payout_'.$data['prize_structure']->id); $returndata['title']=$league->name; $returndata['sport']=$league->sport; if($league->type == 4) { //get the included players $fgd = json_decode($league->feat_game_data); $included_players = json_decode($fgd->included_players); $returndata['included_players']=array(); foreach($included_players as $ip) { $player_info = $this->player_stats->get_player_info($ip); //get team info $pteam = $this->player_stats->get_team_info($player_info->team_id); $matchup = $this->player_stats->get_next_matchup($player_info->team_id); $orig_photo = '/var/www/headshots/'.$player_info->team_id.'/'.$ip.'.jpg'; if(file_exists($orig_photo)) { thumb_trans($orig_photo,'50'); $thumb = 'https://fan-picks.com/headshots/'.$player_info->team_id.'/'.$ip.'_50.jpg'; } else { $dir = dirname($orig_photo); $files = glob($dir . '/*'); $lcaseFilename = strtolower($orig_photo); foreach($files as $file) { if (strtolower($file) == $lcaseFilename) { thumb_trans($file,'50'); $thumb = 'https://fan-picks.com/headshots/'.$player_info->team_id.'/'.$ip.'_50.jpg'; } } if(!isset($thumb)) $thumb = 'assets/fan-picks/img/logo.png'; } $temp=array(); $temp['player_name']=$player_info->first_name.' '.$player_info->last_name; $temp['player_id']=$ip; $temp['position']=$player_info->position; $temp['position2']=$player_info->position2; $temp['event_id']=$matchup->cid; $temp['thumb']=$thumb; $temp['teamcolor']=$pteam->color; $temp['team_name']=$pteam->city.' '.$pteam->name; $temp['number']=$player_info->number; $data['included_players'][]=$temp; } } $returndata['body']=$this->load->view($data['theme'].'/league/lobby_popup',$data,true); //echo "<pre>".print_R($data['sport_data'],true)."</pre>"; echo json_encode($returndata); }
function over_under() { date_default_timezone_set('America/Detroit'); $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); $this->load->model('tracked_events'); $this->form_validation->set_error_delimiters('<p class="help-block">', '</p>'); $data['lang'] = 'english'; $data['theme'] = $this->options->get('theme'); $data['title'] = vlang('game_over_under_title'); $data['extra_js'] = "<script type='text/javascript' src='".site_url('assets/common/js/jquery.countdown.min.js?v='.$this->config->item('ftd_version'))."'></script>"; $data['user'] = $this->users->get_by_id($this->users->id()); $data['user_can_edit'] = 0; if($this->users->is_loggedin() === TRUE) { $this->users->auth_check(); } $league_id=$this->uri->segment(3); $team_id=$data['team_id']=$this->uri->segment(4); $edit=false; if(!empty($team_id)){ $edit=true; } if(empty($league_id)){ //creating new game $league_info=$this->session->userdata('leaguedata'); $data['entries']=$entries=0; $data['entries_text'] = vlang('league_entries_extra_text'); $data['leaguecid'] = ''; $data['entrants'] = ''; $league_info['cid']=''; $temp = array(); $temp['included_players'] = json_encode(explode('|',$league_info['included_players'])); $temp['over_under'] = $league_info['over_under_num']; $league_info['feat_game_data'] = json_encode($temp); } else { $league_info=(array)$this->leagues->get_by_id($league_id); } if($league_info['first_game_cutoff'] < time()) redirect('lobby'); if(isset($league_info["multi_entry"]) && $league_info['multi_entry']==1){ //first try to grab the correct team, if there's no team specified then the user is trying to create a new one if(!empty($team_id)) $league_team = $this->leagues->get_league_team(array('user_id' => $this->users->id(),'league_id' => $league_id,"id"=>$team_id)); else $league_team = false; }else{ //no need to bother with the team id stuff, $league_team = $this->leagues->get_league_team(array('user_id' => $this->users->id(),'league_id' => $league_id)); } if($league_team!=false) $data['user_can_edit'] = 1; $over_under=$this->input->post('over_under'); //no league found - boot if ($league_info === FALSE || (isset($league_info[0]) && $league_info[0] === FALSE)){ $this->session->set_flashdata('error','Problem'); redirect('lobby'); exit; }elseif(isset($league_info['cid'])){ $league_info['id'] = $league_info['cid']; } //If user not logged in, boot them to the login screen if ($league_team === FALSE && $this->users->is_loggedin() === FALSE) { $this->session->set_flashdata('error',vlang('league_login_info')); redirect('login'); } //joining an existing public league if ($this->users->is_loggedin() && $league_team === FALSE && isset($league_info['visibility']) && ($league_info['visibility'] == 'public' || $league_info['visibility'] == 'private')){ $league_team = new stdClass; $league_team->id = 'new'; $league_team->user_id = $this->users->id(); $league_team->created = 0; $league_team->roster = 0; } if ($league_team === FALSE){ //joining a league $this->session->set_flashdata('error',vlang('league_player_select_league_not_found')); redirect('lobby'); }else{ //editing an existing team $data['existing_over_under'] = $existing_over_under = $league_team; } $data['extra_js'] .= "<script type='text/javascript'>var game_type = ".$league_info['type'].";</script>"; //$data['avail_games']=$this->leagues->get_avail_games_by_time_slot($league_info['date'],$league_info['time'],$league_info['sport']); if(!empty($league_info['included_events'])) $data['avail_games']=$avail_games=$this->leagues->get_avail_games_custom($league_info['included_events']); else $data['avail_games']=$avail_games=$this->leagues->get_avail_games_by_time_slot($league_info['date'],$league_info['time'],$league_info['sport']); //determine earliest league play for count-down ticker $countdown_until = $this->leagues->get_games_cutoff_time($data['avail_games']); $data['extra_js'] .= "<script type='text/javascript'>var cutoff_time = new Date(".date('Y, ', $countdown_until).(date('m', $countdown_until) - 1).", ".date('d, H, i, s', $countdown_until).");</script>"; $data['extra_js'] .= "<script type='text/javascript' src='".site_url('assets/'.$data['theme'].'/js/player_select.js?v='.$this->config->item('ftd_version'))."'></script>"; $data['scoring']=$this->options->get('scoring'); $data['sport'] = strtolower($league_info['sport']); $prize_structures_options=$this->leagues->get_prize_structures(); foreach ($prize_structures_options as $pso) { $pid = $pso->id; $title=json_decode($pso->title); //determine # of winners if($pid == $league_info['prize_structure']) { //see if we have a custom prize $fgd=''; if(isset($league_info['feat_game_data'])) { $fgd=$data['fgd']=json_decode($league_info['feat_game_data']); } $company_take = $this->options->get('company_take'); $prize=(isset($fgd->custom_prize) && $fgd->custom_prize!==false)?$fgd->custom_prize:($league_info['size'] * $league_info['entry_fee']); $take=(isset($fgd->custom_rake) && $fgd->custom_rake!==false)?(1-($fgd->custom_rake/100)):(1 - $company_take); $prizetotal=$prize*$take; if(isset($prizetotal)) { switch($league_info['prize_structure']) { case 1: //winner take all $data['winner_text'] = $title->$data['lang'].' : $'.number_format($prizetotal,2,'.',','); break; case 2: //top 3 $data['winner_text'] = $title->$data['lang'].' : $'.number_format($prizetotal*.444,2,'.',',').' / $'.number_format($prizetotal*.333,2,'.',',').' / $'.number_format($prizetotal*.222,2,'.',','); break; case 3: //top 3rd $data['winner_text'] = $title->$data['lang'].' : Each winner $'.number_format($prizetotal/($league_info['size']/3),2,'.',','); break; case 4: //50/50 $data['winner_text'] = $title->$data['lang'].' : Each winner $'.number_format($prizetotal/($league_info['size']/2),2,'.',','); break; case 100: //LFP //these numbers are set by the admin $data['winner_text'] = $title->$data['lang'].' : Total prizes $'.number_format($prizetotal,2,'.',',').' <a href="#lfp_modal" data-toggle="modal" class="question">Learn More</a>'; $lfp=json_decode($league_info['winn_perc_data']); $data['lfp_modal'] = ''; foreach($lfp as $k=>$v){ if (!in_array(($k % 100),array(11,12,13))){ switch ($k % 10) { // Handle 1st, 2nd, 3rd case 1: $k = $k.'st'; break; case 2: $k = $k.'nd'; break; case 3: $k = $k.'rd'; break; default: $k = $k.'th'; break; } } $data['lfp_modal'] .= '<p><strong>'.$k.':</strong> '.$v.'% - $'.number_format($prizetotal*($v/100),2,'.',',').'</p>'; } break; default: $data['winner_text'] = $title->$data['lang']; break; } } else { $data['winner_text'] = $title->$data['lang']; } } } $data['prize_structure']=$this->leagues->get_prize_structure_by_id($league_info['prize_structure']); $data['sport_data']=json_decode($this->options->get('sport_data')); $data['league_info']=$league_info; if(!empty($league_id)){ $data['entries']=count($this->leagues->get_teams_by_league($league_id)); if($data['entries'] < $league_info['size']) { $data['entries_text'] = vlang('league_entries_extra_text'); } else { $data['entries_text'] = ''; } $data['leaguecid'] = $league_info['cid']; //get all teams in the league $sql = 'SELECT * FROM ci_league_team JOIN ci_users on cid = user_id WHERE league_id = "'.$league_id.'" ORDER BY username ASC'; $entrants=$this->db->query($sql); if($entrants->num_rows() > 0) { $data['entrants'] = $entrants->result(); } else { $data['entrants'] = ''; } } else { $data['entrants'] = ''; $data['entries'] = 0; $data['entries_text'] = ''; } if (isset($league_info['size']) && ($league_info['size']) == $data['entries'] && $data['user_can_edit'] == 0){ $this->session->set_flashdata('error',vlang('league_player_select_league_full')); redirect('lobby'); } $data['included_players']=array(); //get the included players $included_players = json_decode($fgd->included_players); foreach($included_players as $ip) { $player_info = $this->player_stats->get_player_info($ip); //get team info $pteam = $this->player_stats->get_team_info($player_info->team_id); $matchup = $this->player_stats->get_next_matchup($player_info->team_id); $orig_photo = '/var/www/headshots/'.$player_info->team_id.'/'.$ip.'.jpg'; if(file_exists($orig_photo)) { thumb_trans($orig_photo,'100'); $thumb = 'https://number1draft.com/headshots/'.$player_info->team_id.'/'.$ip.'_100.jpg'; } else { $dir = dirname($orig_photo); $files = glob($dir . '/*'); $lcaseFilename = strtolower($orig_photo); foreach($files as $file) { if (strtolower($file) == $lcaseFilename) { thumb_trans($file,'100'); $thumb = 'https://number1draft.com/headshots/'.$player_info->team_id.'/'.$ip.'_100.jpg'; } } if(!isset($thumb)) $thumb = 'assets/number1draft/img/logo.png'; } $temp=array(); $temp['player_name']=$player_info->first_name.' '.$player_info->last_name; $temp['player_id']=$ip; $temp['position']=$player_info->position; $temp['position2']=$player_info->position2; $temp['event_id']=$matchup->cid; $temp['thumb']=$thumb; $temp['teamcolor']=$pteam->color; $temp['team_name']=$pteam->city.' '.$pteam->name; $temp['number']=$player_info->number; $data['included_players'][]=$temp; } $data['disabled'] = 0; if(!empty($league_id)){ //we have to find out if over/under slots are full yet if($existing_over_under->roster <= 0) { $this->db->where('league_id',$league_info['cid']); $this->db->where('roster >',0); $over_count = $this->db->count_all_results('league_team'); if($over_count == ($league_info['size']/2)) $data['disabled'] = 1; } if($existing_over_under->roster >= 0) { $this->db->where('league_id',$league_info['cid']); $this->db->where('roster <',0); $under_count = $this->db->count_all_results('league_team'); if($under_count == ($league_info['size']/2)) $data['disabled'] = -1; } } if($data['user_can_edit'] == 0) { $this->form_validation->set_rules('leaguedata', '', 'xss_clean|trim|callback_has_enough_money'); } $this->form_validation->set_rules('over_under', 'Over/Under', 'required|xss_clean|trim'); if ($this->form_validation->run() === FALSE){ }else{ if(!empty($league_info['cid'])){ //League Exists just add the person $league_id=$league_info['cid']; }else{ //League Doesn't exist(because the user is the one creating it) create league then add the person. $league_data=$league_info; $league_data['created']=time(); //echo $data['avail_games'][0]->gamestart; $created_league=true; unset($league_data['included_players']); unset($league_data['over_under_num']); unset($league_data['id']); $league_id=$this->leagues->create($league_data); } $user_id=$this->users->id(); $over_under=$this->input->post('over_under'); if (isset($league_info['size']) && ($league_info['size']) == $data['entries'] && !isset($data['existing_over_under'])){ $this->session->set_flashdata('error',vlang('league_player_select_league_full')); redirect('lobby'); } //need to double check to make sure over/unders didn't fill before submit if ($data['disabled'] > 0 && $over_under > 0) { $this->session->set_flashdata('error',vlang('league_over_under_league_full')); redirect('lobby'); } elseif($data['disabled'] < 0 && $over_under < 0) { $this->session->set_flashdata('error',vlang('league_over_under_league_full')); redirect('lobby'); } $num_existing_entries=0; if (isset($league_info["multi_entry"]) && $league_info["multi_entry"]==1 && $data['user_can_edit'] == 0){ $this->db->where('league_id',$league_id); $this->db->where('user_id',$this->users->id()); $num_existing_entries=$this->db->count_all_results('league_team'); if($num_existing_entries>=$league_info["multi_entry_limit"]){ $this->session->set_flashdata('error',vlang('league_player_select_league_multi_limit')); redirect('lobby'); } } if($data['user_can_edit'] == 0) { } else { $iteration_num = $num_existing_entries; } //add team if joining/creating league if($league_info["multi_entry"]==1){ //first try to grab the correct team, if there's no team specified then the user is trying to create a new one if(!empty($team_id)) { $league_team = $this->leagues->get_league_team(array('user_id' => $this->users->id(),'league_id' => $league_id,"id"=>$team_id)); if($data['user_can_edit'] == 1) { $iteration_num = $league_team->iteration; } else { $iteration_num = $num_existing_entries+1; } } else { $league_team = false; $iteration_num = $num_existing_entries+1; } }else{ //no need to bother with the team id stuff, $league_team = $this->leagues->get_league_team(array('user_id' => $this->users->id(),'league_id' => $league_id)); $iteration_num = 1; } if ($league_team === FALSE) { //ADD NEW TEAM $update=array( "user_id"=>$user_id, "league_id"=>$league_id, "created"=>time(), "roster"=>$over_under, "iteration"=>$iteration_num ); $team_id=$this->leagues->create_team($update); if($team_id === false) { $this->session->set_flashdata('error',"003: ".vlang('league_player_select_create_error')); redirect('/game/over_under/'.$league_id); } else { if (isset($league_info['entry_fee']) && $league_info['entry_fee'] > 0){ //withdraw money $this->user_funds->lock_for_match($this->users->id(), $league_info['entry_fee'], $league_id, $league_info['name']); } $league_info=$this->session->unset_userdata('leaguedata'); $this->session->set_flashdata('cmessage',vlang('league_player_select_create_success_title')); $this->session->set_flashdata('psuccess',vlang('league_player_select_create_success')); redirect('/league/confirm/'.$team_id.'/new'); } }else{ //update team $update=array("roster"=>$over_under); $where = array('user_id' => $this->users->id(), 'league_id' => $league_id, 'id' => $team_id); $this->leagues->edit_team($where, $update); if(isset($temp_team['temp_id'])) { $this->db->delete('league_temp',array('id'=>$temp_team['temp_id'])); $this->session->unset_userdata('temp_league_team'); } $this->session->set_flashdata('cmessage',vlang('league_player_select_edit_success_title')); $this->session->set_flashdata('psuccess',vlang('league_player_select_edit_success')); //redirect('/league/import/'.$team_id); redirect('/league/confirm/'.$team_id); } } $data["body_sport"]=strtolower($league_info['sport']); $this->load->view($data['theme'].'/game/over_under',$data); }
function get_player_stats($player='',$sal_left='',$salary_avg='',$event_id=''){ $this->output->enable_profiler(FALSE); $this->load->model('players'); $this->load->model('player_stats'); if(empty($player)) $player=$this->uri->segment(3); if(empty($sal_left)) $sal_left=$this->uri->segment(4); if(empty($salary_avg)) $salary_avg=$this->uri->segment(5); if(empty($event_id)) $event_id=$this->uri->segment(6); //get player name and position $player_info = $this->player_stats->get_player_info($player); $sport = $player_info->sport; $position = $player_info->position; $team = $player_info->team_id; //if sport is MLB and player is pitcher we need to find out righty/lefty if($sport == 'mlb'&& $position == 'P') { $this->db->where('metakey','handedness-hand'); $this->db->where('player_id',$player); $this->db->where('sport','mlb'); $hand=$this->db->get('sport_player_meta')->row(); $leftright = $hand->metavalue; } $matchup = $this->player_stats->get_next_matchup($team,$event_id); //get next matchup if($sport != 'golf') { //get team info $pteam = $this->player_stats->get_team_info($team); $home_alias = $matchup->home_alias; $visitor_alias = $matchup->visitor_alias; if($home_alias == $pteam->alias) { $home_alias = '<strong>'.$home_alias.'</strong>'; $opponent = $matchup->visitor_name; $opp_id = $matchup->visiting_team_id; } elseif ($visitor_alias == $pteam->alias) { $visitor_alias = '<strong>'.$visitor_alias.'</strong>'; $opponent = $matchup->home_name; $opp_id = $matchup->home_team_id; } } $salary=$this->players->get_salary($player_info->cid,$matchup->cid); //use salary game cap to limit fppg avg $this->db->select('gamecap'); $this->db->where('sport',$sport); $qfppg=$this->db->get('salary_game_cap')->row(); $fppg_cap = $qfppg->gamecap; if($sport == 'mlb' && $position == 'P') { $use_fppg_cap = $fppg_cap/3; } else { $use_fppg_cap = $fppg_cap; } $fppg=round($this->players->get_fppg($player,$use_fppg_cap),1); //$fppg=$this->players->get_fppg($player); $gamestart=$matchup->gamestart; //current season $qcur = $this->db->query('SELECT season FROM ci_sport_event WHERE sport = "'.$sport.'" ORDER BY season DESC LIMIT 1'); $current = $qcur->row(); $current_season = $current->season; if(isset($pteam) && $pteam->color != '') { $teamcolor = $pteam->color; } else { $teamcolor = '#0A3446'; } if($sport != 'golf') { $orig_photo = '/var/www/headshots/'.$player_info->team_id.'/'.$player.'.jpg'; if(file_exists($orig_photo)) { thumb_trans($orig_photo,'170'); $thumb = 'https://number1draft.com/headshots/'.$player_info->team_id.'/'.$player.'_170.jpg'; } else { $dir = dirname($orig_photo); $files = glob($dir . '/*'); $lcaseFilename = strtolower($orig_photo); foreach($files as $file) { if (strtolower($file) == $lcaseFilename) { thumb_trans($file,'170'); $thumb = 'https://number1draft.com/headshots/'.$player_info->team_id.'/'.$player.'_170.jpg'; } } if(!isset($thumb)) $thumb = 'assets/number1draft/img/logo.png'; } } else { $thumb = 'assets/number1draft/img/logo.png'; } if($sport == 'mlb' && ($player_info->position == 'CF' || $player_info->position == 'LF' || $player_info->position == 'RF')) { $data_position = 'OF'; } elseif($sport == 'golf') { $data_position = 'GO'; } else { $data_position = $player_info->position; } if(!empty($player_info->position2)) { if($sport == 'mlb' && ($player_info->position2 == 'CF' || $player_info->position2 == 'LF' || $player_info->position2 == 'RF')) { $data_position2 = 'OF'; } else { $data_position2 = $player_info->position2; } $data_position = $data_position.'/'.$data_position2; } $html = '<div id="player_stats_popup"> <div id="player_stats_left"> <img src="'.$thumb.'" class="player_photo" /> </div> <div id="stats_search_box"> <input type="text" name="stats_search" id="stats_search" placeholder="Search for player" /><button class="btn btn-success stats_search_go">GO</button> </div>'; if($gamestart-(2*86400)<time()){ $html.='<div class="draft_info"> <div><button class="btn btn-success add_player" data-label="'.htmlspecialchars($player_info->first_name.' '.$player_info->last_name,ENT_QUOTES).'" data-id="'.$player_info->cid.'" data-team-id="'.$player_info->team_id.'" data-event-id="'.$event_id.'" data-eventlabel="'.($sport!='golf'?$visitor_alias.'@'.$home_alias:'').'" data-pos="'.$data_position.'" data-salary="'.$salary.'" data-fppg="'.round($fppg,1).'">Draft Player »</button></div> <div class="remaining">Remaining Salary: <span id="salary_left_pop" data-salary-left='.$sal_left.'>$'.number_format((float)$sal_left,0).'</span></div> <div class="average">Avg. Remaining Per Player: <span id="salary_avg_pop" data-salary-rem='.$salary_avg.'>$'.round($salary_avg,0).'</span></div> </div>'; } if($sport != 'golf') { $html .= '<div class="player_name">'.$player_info->first_name.' '.$player_info->last_name.'</div> <div class="player_info" style="background-color: '.$teamcolor.';">'.$pteam->name.' | #'.$player_info->number.' '.$player_info->position.(!empty($player_info->position2)?'/'.$player_info->position2:'').(isset($leftright)?', '.$leftright:'').'<br />'. ($gamestart-(2*86400)<time()?'Salary: $'.number_format($salary):'').'<br />'. 'Next Game: '.$visitor_alias.'@'.$home_alias.' ('.date('m/d g:i A',$gamestart).' EST)</div>'; } else { $html .= '<div class="player_name">'.$player_info->first_name.' '.$player_info->last_name.'</div> <div class="player_info" style="background-color: '.$teamcolor.';">'. ($gamestart-(2*86400)<time()?'Salary: $'.number_format($salary):'').'<br />'. 'Next Tournament: '.date('m/d g:i A',$gamestart).' EST</div>'; } //see if we have cached stats tables for this player, if not create them if($sport != 'golf') { $filedir = '/var/www/playerstats/'.$team.'/'; } else { $filedir = '/var/www/playerstats/golf/'; } $filepath = $filedir.$player.'.html'; $cutofftime = strtotime(date('Y-m-d').' 08:00:00'); //echo date('m/d',time()).'<br />'.date('m/d',$gamestart);exit; if((date('m/d',time()) != date('m/d',$gamestart)) && $sport != 'nfl' && $sport != 'cfb' && $sport != 'golf') { $html .= $this->player_stats->player_stats_cache($player,$event_id,'false'); } else { if(file_exists($filepath)): //if(1==2): $fileupdatetime = filectime($filepath); if($fileupdatetime < $cutofftime): $this->player_stats->player_stats_cache($player,$event_id,'true'); endif; else: $this->player_stats->player_stats_cache($player,$event_id,'true'); endif; $html .= file_get_contents($filepath); } $html .= '<div class="news_wrap"><div class="news_title" style="background-color: '.$teamcolor.';">LATEST PLAYER NEWS</div>'; $html .= '<div class="news_table newscroll">'; $player_news = $this->player_stats->get_player_news($player); if($player_news === false): $html .= '<div class="news_item">No news found</div>'; else: foreach($player_news as $pn): $html .= '<div class="news_item"> <div class="news_date">'.date('F j (g:i A)',$pn['timestamp']).'</div> <div class="news_text"><p>Update: '.$pn['update'].'</p><p>Analysis: '.$pn['analysis'].'</p></div> </div>'; endforeach; endif; $html .= '</div></div>'; $html .= '</div>'; //end of stat box echo $html; }
function create_thumbnails() { //create all thumbnails for sport $sport = $this->uri->segment(3); //now get all the teams $this->db->where('sport',$sport); $teams = $this->db->get('sport_team')->result(); $rootdir = '/var/www/headshots/'; foreach($teams as $t) { $dirf = $rootdir.'/'.$t->cid; $dir = scandir($dirf); foreach($dir as $file) { if(($file != '..') && ($file != '.') && ($file != 'Thumbs.db')) { $orig_photo = $dirf.'/'.$file; thumb_trans($orig_photo,'170'); thumb_trans($orig_photo,'130'); thumb_trans($orig_photo,'100'); } } } echo "done"; }