has('membergroups')){ $sql = "select * from ". $table_prefix ."membergroups "; $stmt = $db->prepare($sql); $stmt->execute(); $membergroupstemp = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($membergroupstemp as $temp) { $membergroups[$temp['id']] = $temp; } $Psr16Adapter->set('membergroups', $courses, $cachetime); // X seconds //} else { // $membergroups = $Psr16Adapter->get('membergroups'); //} if(!$Psr16Adapter->has('courses')){ $sql = "select * from ". $table_prefix ."course order by sorting"; $stmt = $db->prepare($sql); $stmt->execute(); $coursestemp = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($coursestemp as $temp) { $courses[$temp['code']] = $temp; } $Psr16Adapter->set('courses', $courses, $cachetime); // X seconds } else { $courses = $Psr16Adapter->get('courses'); } if (!$select_course) { $default_course = reset($courses); $select_course = $default_course['code']; // $field = 'select_cat'; } if(!$Psr16Adapter->has('course_markers' . $select_course )){ /// $sql = "select " . $table_prefix ."markers.* , " . $table_prefix ."course_markers.name_en, " . $table_prefix ."course_markers.name_zh_hant from ". $table_prefix ."course_markers mc left join ". $table_prefix ."markers m on m.id = cm.market_id where course_code = '" . $select_course . "' order by count" ; $sql = "select " . $table_prefix ."course_markers.* , " . $table_prefix ."markers.name_en, " . $table_prefix ."markers.name_zh_hant, " . $table_prefix ."markers.desp_en, " . $table_prefix ."markers.desp_zh_hant from " . $table_prefix ."course_markers left join " . $table_prefix ."markers on " . $table_prefix ."markers.id = " . $table_prefix ."course_markers.marker_id where course_code = '" . $select_course . "' and code != 'CHECKIN' and code != 'START' order by count"; $stmt = $db->prepare($sql); $stmt->execute(); $course_marker = $stmt->fetchAll(PDO::FETCH_ASSOC); $Psr16Adapter->set('course_markers' . $select_course , $course_marker, $cachetime); // X seconds } else { $course_marker = $Psr16Adapter->get('course_markers' . $select_course ); } $current_course = $courses[$select_course]; $current_membergroups = $membergroups[$select_group]; //d($course_marker); //d($select_course); //d($current_membergroups); /* if ($select_cat) { $cat_where = " and cat = '" . $select_cat . "'"; } */ $course_where = " and course = '" . $select_course . "'"; if(!$Psr16Adapter->has('runner_groups' . $select_course)){ $sql = "select * from ". $table_prefix ."membergroups where course = '" . $select_course . "' order by sorting"; $stmt = $db->prepare($sql); $stmt->execute(); $runner_groupstemp = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($runner_groupstemp as $temp) { $runner_groups[$temp['id']] = $temp; } $Psr16Adapter->set('runner_groups', $runner_groups, $cachetime); // X seconds } else { $runner_groups = $Psr16Adapter->get('runner_groups'); } //d($runner_groups); /* $sql = "select cp_code,count(bibno) as c from ". $table_prefix ."result_public where cp_code is not null group by cp_code"; //d($sql); $stmt = $db->prepare($sql); $stmt->execute(); $overall = $stmt->fetchAll(PDO::FETCH_ASSOC); */ $cachekey = ""; if ($field == "place_group") { $sql = "select * from ". $table_prefix ."runners where group_id = " . $select_group . $course_where . " order by bibno"; $cachekey = "place_group" . $select_course . $select_group; } else if ($field == "place_gender") { $sql = "select * from ". $table_prefix ."runners where gender = '" . $select_gender . "'" . $course_where . " order by bibno"; $cachekey = "place_gender" . $select_course . $select_group .$select_gender; } else { $field = "place_course"; $sql = "select * from ". $table_prefix ."runners where 1=1 " . $course_where ." order by bibno"; $cachekey = "place_course" . $select_course ; } //d($sql); $cachekey = 'runner' . '-' . $select_course . '-' . $cachekey; //if(!$Psr16Adapter->has($cachekey)){ if(1==1){ $stmt = $db->prepare($sql); $stmt->execute(); $runnerstemp = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($runnerstemp as $temp) { if ($showall) { $runner[$temp['bibno']] = $temp; } else if (array_intersect($currentcat, explode(',',$temp['cat']) )) { $runner[$temp['bibno']] = $temp; } } /* $sql = "SELECT `bibno`, max(`updatetime`) AS latestupdatetime , `response` FROM " . $table_prefix . "trackrecord_summary GROUP BY bib"; $stmt = $db->prepare($sql); $stmt->execute(); $responsetemp = $stmt->fetchAll(PDO::FETCH_ASSOC); d(sizeof($responsetemp)) ; foreach ($responsetemp as $temp) { if ($temp['response'] == "yes") { $showresult[] = $temp['bib']; } } */ // d(sizeof($runner)); /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ /*-------------------------------------------------------------*/ $starttime = $current_course['startdatetime']; //$starttime = "2017-01-20 08:30"; if ($field == "place_group") { $sql = "select * from ". $table_prefix . $resulttable . " su left join ". $table_prefix . "runners ru on trim(su.bibno) = trim(ru.bibno) where su.place_group is not null and su.group = " . $select_group . " order by overall_place_group "; } if ($field == "place_gender") { $sql = "select * from ". $table_prefix . $resulttable . " su left join ". $table_prefix . "runners ru on trim(su.bibno) = trim(ru.bibno) where su.place_gender is not null and ru.gender = '" . $select_gender . "' order by overall_place_gender "; } if ($field == "place_course") { $sql = "select su.* from ". $table_prefix . $resulttable . " su left join ". $table_prefix . "runners ru on trim(su.bibno) = trim(ru.bibno) where su.place_course is not null order by overall_place_course "; } if ($field == "place_gender_group") { $sql = "select su.* from ". $table_prefix . $resulttable . " su left join ". $table_prefix . "runners ru on trim(su.bibno) = trim(ru.bibno) where su.place_course is not null order by overall_place_gender_group "; } $stmt = $db->prepare($sql); $stmt->execute(); $resulttemp = $stmt->fetchAll(PDO::FETCH_ASSOC); // d($sql); foreach ($resulttemp as $r) { //$bib = intval($r['bibno']); $bib = str_pad($r['bibno'], 4, '0', STR_PAD_LEFT); $result[$bib] = $r; //$result[$r['bibno']]['result'][$r['cp_code']] = $r[''] if (!$runner[$bib]) { //d($r['bibno']); $incorrectrunner[] = $bib; } else { $runner[$bib][$r['cp_code']] = $r; if (intval($r['overall_place_course'])>0) { $runner[$bib]['overall_place_course'] = $r['overall_place_course']; } if (intval($r['overall_place_gender'])>0) { $runner[$bib]['overall_place_gender'] = $r['overall_place_gender']; } if (intval($r['overall_place_group'])>0) { $runner[$bib]['overall_place_group'] = $r['overall_place_group']; } if (intval($r['overall_place_gender_group'])>0) { $runner[$bib]['overall_place_gender_group'] = $r['overall_place_gender_group']; } if ($field == "place_group") { $runner[$bib]['overall'] = $r['overall_place_group']; } if ($field == "place_gender") { $runner[$bib]['overall'] = $r['overall_place_gender']; } if ($field == "place_course") { $runner[$bib]['overall'] = $r['overall_place_course']; } if ($field == "place_gender_group") { $runner[$bib]['overall'] = $r['place_gender_group']; } } } //d($runner); usort($runner, function($a, $b) { if ($a['overall'] || $b['overall']) { if ($a['overall'] == "") return 1; if ($b['overall'] == "") return -1; return $a['overall'] - $b['overall']; } else { return intcmp($a['bibno'], $b['bibno']); } }); $Psr16Adapter->set($cachekey , $runner, $cachetime); // X seconds // d('not cached'); } else { $runner = $Psr16Adapter->get($cachekey); // d('cached'); } if ($current_membergroups['israceteam']) { $runner = array(); $sql = "select * from ". $table_prefix . "teams_summary where group_id = " . $select_group . " order by slowest_cp_count desc, -place_group desc, -slowest_recorddatetime desc "; $stmt = $db->prepare($sql); $stmt->execute(); $runnertemp = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($runnertemp as $temp){ $runner[$temp['bibno']] = $temp; } } /*-------------------------------------------------------------*/ foreach ($runner as $key=>$r) { if ($r['firstname'] == "SPARE") unset($runner[$key]); } /*-------------------------------------------------------------*/ /*--------------------------------------- summary ----------------------*/ $totalrunner = sizeof($runner); //SELECT count(*) FROM `fourtrailsmini2017a_runners` WHERE FIND_IN_SET('9',cat) or FIND_IN_SET('13',cat) //$totalrunner = 1060; //$totalcheckin = 0; //foreach ($runner as $r) { // if ($r['CHECKIN'] || ($r['CP1']) || ($r['CP2']) || ($r['CP3']) || ($r['FINISH']) ) // $totalcheckin++; //} /* $totalmidpoint = 0; foreach ($runner as $r) { if ($r['MIDPOINT']) $totalmidpoint++; } $totalfinish = 0; foreach ($runner as $r) { if ($r['FINISH']) $totalfinish++; } */ //d($runner); //d($totalrunner); //d($totalcheckin); //d($totalfinish); //d($totalmidpoint); //$checkinprecent = ceil(($totalcheckin/$totalrunner) * 100); //$midpointprecent = ceil(($totalmidpoint/$totalcheckin) * 100); //$finishprecent = ceil(($totalfinish/$totalcheckin) * 100); /* d($checkinprecent); d($midpointprecent); d($finishprecent); */ //if ($midpointprecent > 100) $midpointprecent = 100; //if ($finishprecent > 100) $finishprecent = 100; //if ($checkinprecent > 100) $checkinprecent = 100; /*-------------------------------------------------------------*/ if ($field == "place_group") { $arrivechartwhere = " and su.place_group is not null and su.group = " . $select_group ; } if ($field == "place_gender") { $arrivechartwhere = " and su.place_gender is not null and ru.gender = '" . $select_gender . "'" ; } if ($field == "place_course") { $arrivechartwhere = " and su.place_course is not null "; } //d($runner); //uasort($runner, "cmp"); //array_orderby($runner, ['FINISH'][$field], SORT_NATURAL , SORT_STRING ); //d($runner); ?>

1) { foreach ($courses as $course) { echo ''; } } ?>
'; echo ''; echo i18n_text("Overall Ranking"); echo ''; echo '
'; //echo ' '; echo ''; echo i18n_text("Male Group"); echo ''; echo ''; //echo ' '; echo ''; echo i18n_text("Female Group"); echo ''; echo ''; foreach ($runner_groups as $group) { //echo ' '; echo ''; echo i18n_field( $group, "name"); echo ''; echo ''; } ?>

">
'; /* echo ''; */ echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; $rowcount =0; foreach ($runner as $r) { //d($r['FINISH']); $hit = 0; $status= ""; echo ''; echo ''; echo ''; echo ''; $temp = json_decode($r['teamrecord'],1); echo ''; echo ''; echo ''; } ?>
'; echo "#"; echo ''; echo i18n_text("Place"); echo ''; echo 'BIB'; echo ''; echo i18n_text("Team"); echo ''; echo 'Check Point'; echo ''; echo 'Time'; echo ''; echo '
'; echo $r['place_group']; echo ''; echo $r['bibno']; echo ''; echo $r['name']; if ($r['nameonbadge']) echo ' (' . trim($r['nameonbadge']) . ')'; echo ''; echo $r['slowest_cp_code']; echo ''; $tempmin = null; foreach ($temp as $t) { if ($t['duration'] > $tempmin || $tempmin == null ) { $tempmin = $t['duration']; $tempmin2 = $t['slowest_recorddatetime']; } } echo Duration($tempmin, false, true); echo '
'; echo '
'; if ($tempmin2 != '0000-00-00 00:00:00') { echo $r['slowest_recorddatetime']; } echo '
'; echo '
'; echo '
'; echo '總共報名人數: ' . $r['regedmember']; echo '
'; echo '到達最後check point : ' . $r['atfastercpmember'] . "%"; echo '

'; foreach ($temp as $t) { echo '
'; echo $t['bibno'] . ' ' . $t['firstname'] . ' ' . $t['lastname'] . ' ' . $t['nameonbadge'] . ' ' . $t['gender']; echo '
'; echo '
'; echo $t['cp_code']; echo ' : '; echo Duration($t['duration'], false, true); echo '
'; if ( $t['cp_code'] == "FINISH") { echo ''; echo ''; echo "
" . i18n_text("Download Certificate") . "
"; echo '
'; } echo '
'; } echo '
'; /* echo ''; */ echo ''; echo ''; echo ''; if ($field == "place_course") { echo ''; } foreach ($course_marker as $marker) { echo ''; } // echo ''; echo ''; echo ''; echo ''; $rowcount =0; // d($runner); foreach ($runner as $r) { //d($r['FINISH']); $hit = 0; $status= ""; foreach ($course_marker as $market) { if ($r[$market['code']][$field]) { $hit = 1; } } if ($hit == 0) { $status= "DNS"; } else if (!$r['FINISH'][$field] ) { $status= "DNF"; } /* if (!$r['FINISH'][$field] && !$r['CP1'][$field] && !$r['CP2'][$field] && !$r['CP3'][$field] && !$r['CHECKIN'][$field] && !$r['START'][$field]) { } if (!$r['FINISH'][$field] && ($r['CP1'][$field] || $r['CP2'][$field] || $r['CP3'][$field] || $r['CHECKIN'][$field] || $r['START'][$field])) { $status= "DNF"; } */ //d($select_course); //d(explode(',',$r['course'])); //var_dump(array_intersect(array($select_course), explode(',',$r['course']) )); if (array_intersect(array($select_course), explode(',',$r['course']) )) { $warning = false; } else { $warning = true; } if ($warning == true && $status == "DNS") { } else { if (!$warning) { echo ''; } else { echo ''; } /* $rowcount++; echo ''; */ echo ''; echo ''; echo ''; if ($field == "place_course") { echo ''; } /* echo ''; foreach ($course_marker as $marker) { echo ''; } //echo ''; /* echo ''; echo ''; */ //echo ''; echo ''; echo ''; echo ''; } //d($r); } ?>
'; echo "#"; echo ''; echo i18n_text("Place"); echo ''; echo 'BIB'; echo ''; echo i18n_text("Name"); echo ''; echo i18n_text("Gender"); echo ''; echo i18n_field($marker, 'name'); echo '
' . i18n_field($marker, 'desp') . '
'; echo '
'; // echo i18n_text("Finish"); // echo '
城門水塘主壩Shing Mun Reservoir
'; // echo '
'; echo ''; echo '
'; echo $rowcount; echo ''; if ($status) { echo $status; } else { echo $r['FINISH'][$field]; } echo ''; echo $r['bibno']; echo ''; if ($r['israceteam']) { echo $r['raceteam']; } else { echo displayFirstLastname($r['firstname'], $r['lastname']); } if ($r['nameonbadge']) echo ' (' . trim($r['nameonbadge']) . ')'; /* if ( $r['CHECKIN']['recorddatetime']) { echo '
'; echo i18n_text("Check In") . ":" ; echo $r['CHECKIN']['recorddatetime']; echo '
'; } */ //$cats = explode(",", $r['cat']); //if (!in_array(2,$cats)) //echo 'xxxxxxxxxxx'; echo '
'; echo $r['gender']; echo ''; if($r['START']['recorddatetime']) { //echo Duration($r['START']['duration'], false, true); echo '
'; echo $r['START']['recorddatetime']; echo '
'; } */ //if ($r['START'][$field]) { // echo ' (' . $r['START'][$field] . ')'; // echo ''; //} echo '
'; echo displaytimeblock($r[$marker['code']]); echo ''; //echo displaytimeblock($r['CP1']); //echo ''; echo displaytimeblock($r['CP2']); echo ''; echo displaytimeblock($r['CP3']); echo ''; //echo displaytimeblock($r['FINISH']); //if ($r['FINISH'][$field]) { //echo ' (' . $r['FINISH'][$field] . ')'; //echo ''; //} //echo ''; if ($r['FINISH']['place_course']) { echo ''; echo ''; echo ''; echo ''; echo ''; if ($r['FINISH']['place_group'] && $runner_groups[$r['group_id']]['id'] ) { echo ''; echo ''; echo ''; echo ''; } echo ''; echo ''; echo ''; echo ''; echo '
'; echo i18n_text("Overall Ranking") . ":"; echo ''; echo $r['FINISH']['place_course']; echo '
'; //echo i18n_text("Cat. Ranking") . ":"; echo i18n_field($runner_groups[$r['group_id']],'name'); echo ' '; echo i18n_text("Ranking") . ":"; echo ''; echo $r['FINISH']['place_group']; echo '
'; //d($r); if ($r['gender']) { if ($r['gender'] == "M") { echo i18n_text("Male Group"); } if ($r['gender'] == "F") { echo i18n_text("Female Group"); } echo ' '; echo i18n_text("Ranking") . ":"; echo ''; echo $r['FINISH']['place_gender']; } echo '
'; } echo '
'; if ( $r['FINISH']['duration'] > 0) { echo ''; echo ''; echo "
" . i18n_text("Download Certificate") . "
"; echo '
'; } echo '
'; $ret .= Duration($r['duration'], false, true); $ret .= ''; // if ($r['chiptime']) { // $ret .= '
'; // $ret .= 'Chip time'; // $ret .= '
'; // $ret .= '
'; // $ret .= Duration($r['chiptime'], false, true); // $ret .= '
'; // } $ret .= '
'; $ret .= $r['recorddatetime']; $ret .= '
'; //if ($r[$field]) { // echo '(' . $r[$field] . ')'; //} } return $ret; } function intcmp($a,$b) { if((int)$a == (int)$b)return 0; if((int)$a > (int)$b)return 1; if((int)$a < (int)$b)return -1; } function cmp($a, $b) { global $field; if ( !$a['FINISH'][$field] && !$b['FINISH'][$field] && !$a['CP3'][$field] && !$b['CP3'][$field] && !$a['CP2'][$field] && !$b['CP2'][$field] && !$a['CP1'][$field] && !$b['CP1'][$field] && !$a['START'][$field] && !$b['START'][$field] && !$a['CHECKIN'][$field] && !$b['CHECKIN'][$field] ) { return intcmp($a['bibno'], $b['bibno']); } /*-------------*/ if ($a['FINISH'][$field] && $b['FINISH'][$field]) return intcmp($a['FINISH'][$field], $b['FINISH'][$field]); if ($a['FINISH'][$field] && !$b['FINISH'][$field]) return -1; if (!$a['FINISH'][$field] && $b['FINISH'][$field]) return 1; /*------------ if ($a['CP3'][$field] && $b['CP3'][$field]) return intcmp($a['CP3'][$field], $b['CP3'][$field]); if ($a['CP3'][$field] && !$b['CP3'][$field]) return -1; if (!$a['CP3'][$field] && $b['CP3'][$field]) return 1; ------------*/ /*-------------*/ if ($a['CP2'][$field] && $b['CP2'][$field]) return intcmp($a['CP2'][$field], $b['CP2'][$field]); if ($a['CP2'][$field] && !$b['CP2'][$field]) return -1; if (!$a['CP2'][$field] && $b['CP2'][$field]) return 1; /*-------------*/ if ($a['CP1'][$field] && $b['CP1'][$field]) return intcmp($a['CP1'][$field], $b['CP1'][$field]); if ($a['CP1'][$field] && !$b['CP1'][$field]) return -1; if (!$a['CP1'][$field] && $b['CP1'][$field]) return 1; /*-------------*/ /*-------------*/ if ($a['START'][$field] && $b['START'][$field]) return intcmp($a['START'][$field], $b['START'][$field]); if ($a['START'][$field] && !$b['START'][$field]) return -1; if (!$a['START'][$field] && $b['START'][$field]) return 1; /*-------------*/ if (!$b['CHECKIN'][$field]) return -1; if (!$a['CHECKIN'][$field]) return 1; if ($a['CHECKIN'][$field] || $b['CHECKIN'][$field]) return intcmp($a['CHECKIN'][$field], $b['CHECKIN'][$field]); /* if (!$b['CHECKIN'][$field]) return -1; if (!$a['CHECKIN'][$field]) return 1; if ($a['CHECKIN'][$field] || $b['CHECKIN'][$field]) return strcmp($a['CHECKIN'][$field], $b['CHECKIN'][$field]); */ return intcmp($a['bibno'], $b['bibno']); } ?>