示例#1
0
 function update_games($games)
 {
     $holeplay = "";
     $course_id = "";
     $course_length_id = "";
     $lanjut = false;
     $SQL = "select";
     $SQL .= "  games_id,";
     $SQL .= "  games_date,";
     $SQL .= "  games_type,";
     $SQL .= "  games_weather,";
     $SQL .= "  games_note,";
     $SQL .= "  games_holeplay,";
     $SQL .= "  course_id,";
     $SQL .= "  course_length_id,";
     $SQL .= "  members_id ";
     $SQL .= " from t_games ";
     $SQL .= " where ";
     $SQL .= "  games_id = '" . $games->games_id . "'";
     $this->SimpleDB->connect();
     $rst = $this->SimpleDB->query($SQL);
     $this->SimpleDB->disconnect();
     if (is_object($rst) && $rst->next()) {
         $holeplay = $rst->get(5);
         $course_id = $rst->get(6);
         $course_length_id = $rst->get(7);
         $lanjut = true;
     }
     if ($lanjut) {
         $SQL = "update t_games set";
         $SQL .= "  games_date='" . $games->games_date . "',";
         $SQL .= "  games_weather='" . $games->games_weather . "',";
         $SQL .= "  games_note='" . $games->games_note . "',";
         $SQL .= "  games_holeplay=" . $games->games_holeplay . ",";
         $SQL .= "  course_id=" . $games->course_id . ",";
         $SQL .= "  course_length_id=" . $games->course_length_id . ",";
         $SQL .= "  members_id='" . $games->members_id . "'";
         $SQL .= " where ";
         $SQL .= "  games_id = '" . $games->games_id . "'";
         $this->SimpleDB->connect();
         $this->SimpleDB->execute($SQL);
         $this->SimpleDB->disconnect();
         if ($games->course_id != $course_id || $games->course_length_id != $games->course_length_id || $games->games_holeplay != $holeplay) {
             $SQL = "delete from t_games_result where games_id = '" . $games->games_id . "'";
             $this->SimpleDB->connect();
             $this->SimpleDB->execute($SQL);
             $this->SimpleDB->disconnect();
             $SQL = "delete from t_games_score where games_id = '" . $games->games_id . "'";
             $this->SimpleDB->connect();
             $this->SimpleDB->execute($SQL);
             $this->SimpleDB->disconnect();
             $course = new course($games->course_id);
             $par = $course->get_detail();
             $tee = $course->getTee($games->course_length_id);
             switch ($games->games_holeplay) {
                 case 1:
                     $first_hole = 0;
                     $last_hole = 18;
                     break;
                 case 2:
                     $first_hole = 0;
                     $last_hole = 8;
                     break;
                 case 3:
                     $first_hole = 9;
                     $last_hole = 18;
                     break;
                 default:
                     $first_hole = 0;
                     $last_hole = 18;
                     break;
             }
             for ($i = $first_hole; $i < $last_hole; $i++) {
                 $val_par = $par['hole'][$i]['par'];
                 $val_hcp = $par['hole'][$i]['hcp'];
                 $val_lng = $tee['hole'][$i]['length'];
                 $k = $i + 1;
                 $SQL = "insert into t_games_score(";
                 $SQL .= "  games_id,";
                 $SQL .= "  hole_no,";
                 $SQL .= "  hole_length,";
                 $SQL .= "  hole_par,";
                 $SQL .= "  hole_hcp,";
                 $SQL .= "  hole_score)";
                 $SQL .= " values(";
                 $SQL .= "  '" . $games->games_id . "',";
                 $SQL .= "  " . $k . ",";
                 $SQL .= "  " . $val_lng . ",";
                 $SQL .= "  " . $val_par . ",";
                 $SQL .= "  " . $val_hcp . ", 0)";
                 $this->SimpleDB->connect();
                 $this->SimpleDB->execute($SQL);
                 $this->SimpleDB->disconnect();
             }
             $SQL = "insert into t_games_result(";
             $SQL .= "  games_id)";
             $SQL .= " values(";
             $SQL .= "  '" . $games->games_id . "')";
             $this->SimpleDB->connect();
             $this->SimpleDB->execute($SQL);
             $this->SimpleDB->disconnect();
         }
     }
 }