### Eclipse Workspace Patch 1.0
#P leaguesite
Index: leaguesite_match/leaguesite_match.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/leaguesite/leaguesite_match/leaguesite_match.module,v
retrieving revision 1.30
diff -u -r1.30 leaguesite_match.module
--- leaguesite_match/leaguesite_match.module	5 Jul 2010 17:40:32 -0000	1.30
+++ leaguesite_match/leaguesite_match.module	20 Jul 2010 21:26:09 -0000
@@ -1,5 +1,7 @@
 <?php
-// $Id: leaguesite_match.module,v 1.30 2010/07/05 17:40:32 alun Exp $
+// $Id: leaguesite_match.module,v 1.22 2010/05/09 21:08:45 alun Exp $
+
+module_load_include('inc', 'date', 'date_api_elements');
 
 /**
 * Implementation of hook_perm()
@@ -135,14 +137,6 @@
 function leaguesite_match_form(&$node, $form_state) {
 	$form['#cache'] = TRUE;
 	$form['#validate'][] = 'leaguesite_match_custom_validate';
-  //check the starting time and compare to the default starting time
-  if($node->match_hour != ''){
-    $start_hour = $node->match_hour;
-    $start_minute = $node->match_minute;
-  }else{
-    $start_hour = variable_get('leaguesite_match_start_time_hour', '');
-    $start_minute = variable_get('leaguesite_match_start_time_minute', '');
-  }
   
   
   //get the possible seasons from the database - the most recent (or current) is the most likely
@@ -328,32 +322,23 @@
     '#weight' => 4,
   );
   
-  $form['date'] = array(
-    '#type' => 'fieldset',
+  if(isset($node->match_time)){
+    $current_date = date_format_date(date_timezone_set(date_make_date($node->match_time, 'UTC', DATE_UNIX), date_default_timezone()), 'custom', 'Y-m-d H:i');
+  }else{
+  	$current_date = date_format_date(date_make_date('now', 'NULL', 'DATE_UNIX'), 'custom', 'Y-m-d');
+  	$current_date .= ' '.variable_get('leaguesite_match_start_time_hour', '14').':'.variable_get('leaguesite_match_start_time_minute', '00'); 
+  }
+  
+  
+  $form['match_time'] = array(
+    '#type' => 'date_popup',
     '#title' => t('The date and start time for the match'),
+    '#date_format' => 'd.m.Y.H:i',
+    '#date_year_range' => '-3:+5',
+    '#default_value' =>  $current_date,//date_make_date($node->match_time),
     '#weight' => -6,
   );
-  $form['date']['match_time'] = array(
-    '#type' => 'date',
-    '#title' => t('Match Date'),  
-    '#required' => TRUE,
-    '#weight' => -1,
-    '#default_value' => $node->match_time,
-  );
-  $form['date']['match_hour'] = array(
-    '#type' => 'select',
-    '#title' => 'hour',
-    '#required' => TRUE,
-    '#options' => $hours,
-    '#default_value' => $start_hour,
-  );
-  $form['date']['match_minute'] = array(
-    '#type' => 'select',
-    '#title' => 'minute',
-    '#required' => TRUE,
-    '#options' => $mins,
-    '#default_value' => $start_minute,
-  );
+  
   $form['body_filter']['body'] = array(
     '#type' => 'textarea',
     '#title' => t('Match Notes'),
@@ -411,7 +396,7 @@
 function leaguesite_match_load($node){
   if($node->type == 'leaguesite_match'){
     //get the additional match information and attach to the node
-    $teams = db_fetch_array(db_query("SELECT {leaguesite_relation}.relation_type, {leaguesite_relation}.sport_id AS sport, {leaguesite_match}.home_team, {leaguesite_match}.away_team, home.title AS home_name, away.title AS away_name, {leaguesite_match}.home_score, {leaguesite_match}.away_score, {leaguesite_match}.match_time, {leaguesite_match}.is_result, {leaguesite_match}.relation_id, {leaguesite_league}.sport_id FROM {leaguesite_match} LEFT JOIN {node} home ON {leaguesite_match}.home_team = home.nid LEFT JOIN {node} away ON {leaguesite_match}.away_team = away.nid LEFT JOIN {leaguesite_relation} ON {leaguesite_match}.relation_id = {leaguesite_relation}.relation_id LEFT JOIN {leaguesite_league} ON {leaguesite_relation}.lid = {leaguesite_league}.lid WHERE {leaguesite_match}.nid = %d;", intval($node->nid)));
+    $teams = db_fetch_array(db_query("SELECT {leaguesite_relation}.relation_type, {leaguesite_relation}.sport_id AS sport, {leaguesite_match}.home_team, {leaguesite_match}.away_team, home.title AS home_name, away.title AS away_name, {leaguesite_match}.matchday, {leaguesite_match}.home_score, {leaguesite_match}.away_score, {leaguesite_match}.match_time, {leaguesite_match}.is_result, {leaguesite_match}.relation_id, {leaguesite_league}.sport_id FROM {leaguesite_match} LEFT JOIN {node} home ON {leaguesite_match}.home_team = home.nid LEFT JOIN {node} away ON {leaguesite_match}.away_team = away.nid LEFT JOIN {leaguesite_relation} ON {leaguesite_match}.relation_id = {leaguesite_relation}.relation_id LEFT JOIN {leaguesite_league} ON {leaguesite_relation}.lid = {leaguesite_league}.lid WHERE {leaguesite_match}.nid = %d;", intval($node->nid)));
     $node->is_result = $teams['is_result'];
     $node->home_team = $teams['home_team'];
     $node->away_team = $teams['away_team'];
@@ -423,11 +408,11 @@
     }else{
     	//Get the sport of the match from its league.
     	$node->sport = $teams['sport_id'];
+    	$node->matchday = $teams['matchday'];
     }
     $node->match_type = $teams['relation_type'];
-    $node->match_time = array('year' => format_date($teams['match_time'], 'custom', 'Y', 0),  'month' => format_date($teams['match_time'], 'custom', 'n', 0), 'day' => format_date($teams['match_time'], 'custom', 'j', 0));
-    $node->match_hour = format_date($teams['match_time'], 'custom', 'G', 0);
-    $node->match_minute = format_date($teams['match_time'], 'custom', 'i', 0);
+    $node->match_time = $teams['match_time'];
+
     //check if the score has not been entered yet
     if($teams['is_result'] == 0){
       $node->home_score = '';
@@ -458,7 +443,13 @@
     $node->is_result = 1;
   }
   module_invoke_all('leaguesite_match_insert', $node);
-  $match_time = mktime($node->match_hour, $node->match_minute, 0, intval($node->match_time['month']), intval($node->match_time['day']), intval($node->match_time['year']));
+  $match_time = $node->match_time;
+  $match_time = date_make_date($match_time, date_default_timezone(), DATE_ISO);
+  
+  $match_time = date_timezone_set($match_time, timezone_open('UTC'));
+
+  //$date now contains the UTC value of the date.
+  $match_time = date_format_date($match_time, 'custom', 'U');
   
   db_query("INSERT INTO {leaguesite_match} (nid, home_team, away_team, match_time, home_score, away_score, is_result, relation_id, matchday) VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d, %d)", intval($node->nid), intval($node->home_team), intval($node->away_team), $match_time, check_plain($node->home_score), check_plain($node->away_score), intval($is_result), intval($node->season_league), intval($node->matchday));
   if($node->op == t('Save and enter players')){
@@ -503,7 +494,17 @@
   //call leaguesite hook for an updated game. This allows modules to see both the old and new score before we update the database.
   module_invoke_all('leaguesite_match_update', $node);
   
-  $match_time = mktime($node->match_hour, $node->match_minute, 0, intval($node->match_time['month']), intval($node->match_time['day']), intval($node->match_time['year']));
+  $match_time = $node->match_time;
+  //print $node->match_time.' ';
+  
+  $match_time = date_make_date($match_time, date_default_timezone(), DATE_ISO);
+  //print_r ($match_time);
+  $match_time = date_timezone_set($match_time, timezone_open('UTC'));
+  //print $match_time.' ';
+  //$date now contains the UTC value of the date.
+  $match_time = date_format_date($match_time, 'custom', 'U');
+  //print $match_time;
+  
   db_query("UPDATE {leaguesite_match} SET home_team = %d, away_team = %d, match_time = %d, home_score = '%s', away_score = '%s', is_result = %d, relation_id = %d, matchday = %d WHERE nid = %d;", intval($node->home_team), intval($node->away_team), $match_time, check_plain($node->home_score), check_plain($node->away_score), intval($is_result), intval($node->season_league), intval($node->matchday), intval($node->nid));
   if($node->op == t('Save and enter players')){
     drupal_goto('node/'.$node->nid.'/edit/match_players');
@@ -711,11 +712,12 @@
 function leaguesite_match_view($node, $teaser = FALSE, $page = FALSE){
 	$node = node_prepare($node, $teaser);
   //get the extra information from the database
+  
+  
   if(variable_get('leaguesite_match_display_date', TRUE)){
 	  $match_info = db_fetch_array(db_query("SELECT {leaguesite_match}.* FROM {leaguesite_match} WHERE {leaguesite_match}.nid = %d LIMIT 1", $node->nid));
-	  $node->content['match_time'] = array('#value' => format_date($match_info['match_time'], 'large', '', 0), '#weight' => -4, '#prefix' => '<div id="leaguesite_match_time">', '#suffix' => '</div>');
+	  $node->content['match_time'] = array('#value' => date_format_date(date_timezone_set(date_make_date($node->match_time, 'UTC', DATE_UNIX), date_default_timezone()), 'large', '', 0), '#weight' => -4, '#prefix' => '<div id="leaguesite_match_time">', '#suffix' => '</div>');
   }
-  //TODO: I should be able to call drupal to continue adding its own content here, shouldn't I? body and teasers are not loaded when this hook is used.
   
   
   //if the scoring module is enabled and the match is a result, we should check for scoring details
Index: leaguesite_match/leaguesite_match.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/leaguesite/leaguesite_match/leaguesite_match.admin.inc,v
retrieving revision 1.22
diff -u -r1.22 leaguesite_match.admin.inc
--- leaguesite_match/leaguesite_match.admin.inc	5 Jul 2010 17:40:32 -0000	1.22
+++ leaguesite_match/leaguesite_match.admin.inc	20 Jul 2010 21:26:09 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: leaguesite_match.admin.inc,v 1.22 2010/07/05 17:40:32 alun Exp $
+// $Id: leaguesite_match.admin.inc,v 1.12 2010/04/15 18:35:03 alun Exp $
 
 function leaguesite_match_admin(){
   $output = '';
@@ -268,14 +268,16 @@
         '#value' => $node->title,
       );
       
+      $match_day = date_format_date(date_timezone_set(date_make_date($node->match_time, 'UTC', DATE_UNIX), date_default_timezone()), 'custom', 'd/m');
+      $match_time = date_format_date(date_timezone_set(date_make_date($node->match_time, 'UTC', DATE_UNIX), date_default_timezone()), 'custom', 'H:i');
       $form[$count]['match_date'.$count] = array(
         '#type' => 'hidden',
-        '#value' => $node->match_time['day'].'/'.$node->match_time['month'],
+        '#value' => $match_day,
       );
       
       $form[$count]['match_time'.$count] = array(
         '#type' => 'hidden',
-        '#value' => $node->match_hour.':'.$node->match_minute,
+        '#value' => $match_time,
       );
       $form[$count]['match_id'.$count] = array(
         '#type' => 'hidden',
