Class Liga{
public function __construct() {
global $wpdb;
$this->db = $wpdb;
}
public function get_teams(){
$teams = $this->db->get_results("SELECT * FROM uks_posts WHERE post_type='druzyny' AND post_status='publish' ORDER BY post_title ASC ");
return $teams;
}
public function get_games(){
$games = $this->db->get_results("SELECT * FROM uks_liga WHERE active!='0' ORDER BY game DESC ");
return $games;
}
public function get_game($g){
$game = $this->db->get_results("SELECT * FROM uks_liga WHERE id='$g' ");
return $game[0];
}
public function add_game($team1,$team2,$game,$place){
if($this->db->insert('uks_liga',
array(
'team1'=>$team1,
'team2'=>$team2,
'game'=>$game,
'place'=>$place,
'active'=>'1'
),
array(
'%d',
'%s',
'%s',
'%s',
'%d'
)
)!==false){
return true;
}else{
return false;
}
}
public function update_game($id,$team1,$team2,$game,$place,$score1,$score2){
if($this->db->update('uks_liga',
array(
'team1'=>$team1,
'team2'=>$team2,
'game'=>$game,
'place'=>$place,
'team1_score'=>$score1,
'team2_score'=>$score2
),
array("id"=> $id),
array(
'%d',
'%s',
'%s',
'%s',
'%d'
)
)!==false){
return true;
}else{
return false;
}
}
public function delete_game($id){
if($this->db->update('uks_liga',
array(
'active'=>0
),
array("id"=> $id),
array('%d')
)!==false){
return true;
}else{
return false;
}
}
public function get_coming_games($team=0,$limit=6){
$add = $team!=0 ? "AND team1='$team'" : "";
$games = $this->db->get_results("SELECT * FROM uks_liga WHERE active!='0' AND game >= NOW() $add ORDER BY game DESC LIMIT $limit");
return $games;
}
public function get_past_games($team=0,$limit=10){
$add = $team!=0 ? "AND team1='$team'" : "";
$games = $this->db->get_results("SELECT * FROM uks_liga WHERE active!='0' AND game <= NOW() $add ORDER BY game DESC LIMIT $limit");
return $games;
}
}
?> function liga_games(){
$l = new Liga();
?>
if($_GET["success"]=='1'){
?>
}elseif($_GET["success"]=='2'){
?>
}elseif($_GET["success"]=='3'){
?>
}?>
Rozgrywki
Drużyna |
Przeciwnik |
Miejsce |
Data |
Wynik |
Edytuj |
Usuń |
foreach($l->get_games() as $k=>$g){
$alt= $k % 2 == 0 ? "alternate" : "";
if($g->team1_score=="" || $g->team2_score==""){
if (strtotime($g->game) < time()) {
$score="Nie podano";
}else{
$score="-";
}
}else{
$score=$g->team1_score.':'.$g->team2_score;
};?>
|
|
|
01.01.70 00:00 |
|
|
Czy chcesz usunąć ten mecz? Anuluj
|
}?>
}
?> function liga_game_form(){
$l = new Liga();
$teams = $l->get_teams();
if($_GET["game_id"]!=''){
var_dump($_GET['game_id']);
$vals = $l->get_game($_GET['game_id']);
}else{
$vals = [];
$title="Dodaj mecz";
}
wp_enqueue_script('jquery-ui-datepicker');
wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
wp_enqueue_style('jquery-ui');
?>
if($_GET['eval']=="1"){
?>
Podaj datę w formacie dd.mm.yyyy
}
if($_GET['eval'=='2']){
?>
Coś poszło nie tak, nie zapisano meczu do bazy danych
}
?>
}
?>// if(!$_POST){ die();}
function save_game(){
$l = new liga();
if(isSet($_POST["game"])){
//saving
if($_POST["game"]==""){
//new
//eval
if(strlen($_POST['gdate'])!=10){
wp_redirect(admin_url('admin.php?page=liga_game_form&eval=1'));
}else{
list($d,$m,$y) = explode(".",$_POST['gdate']);
$dt=$y."-".$m."-".$d." ".$_POST['gtime'].":00";
if($l->add_game($_POST["team1"],$_POST["team2"],$dt,$_POST["place"])){
wp_redirect(admin_url('admin.php?page=liga_games&success=1'));
}else{
wp_redirect(admin_url('admin.php?page=liga_game_form&eval=2'));
}}
}else{
//update
list($d,$m,$y) = explode(".",$_POST['gdate']);
$dt=$y."-".$m."-".$d." ".$_POST['gtime'].":00";
if($l->update_game($_POST["game"],$_POST["team1"],$_POST["team2"],$dt,$_POST["place"],$_POST["team1_score"],$_POST["team2_score"])){
wp_redirect(admin_url('admin.php?page=liga_games&success=2'));
}else{
wp_redirect(admin_url('admin.php?page=liga_game_form&eval=2'));
}
}
}
}
function del_game(){
$l = new liga();
$l->delete_game($_POST["game"]);
wp_redirect(admin_url('admin.php?page=liga_games&success=3'));
}
?>
{"version":"1.0","provider_name":"MKS Grochovia Warszawa - Klub pi\u0142karski Groch\u00f3w","provider_url":"https:\/\/grochovia.pl","author_name":"MattGebb","author_url":"https:\/\/grochovia.pl\/author\/mattgebb\/","title":"M\u0142odziki po jedenastu - MKS Grochovia Warszawa - Klub pi\u0142karski Groch\u00f3w","type":"rich","width":600,"height":338,"html":"
M\u0142odziki po jedenastu<\/a><\/blockquote>