Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $allowedExts = array("xls", "xlsx");
- include_once 'include/Config.php';
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "stats";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- } else {
- echo 'connected<br/>';
- }
- $nextGameID =$conn->query("SELECT MAX(game_id) `max` FROM game");
- if (!$nextGameID) die($conn->error);
- while($row=mysqli_fetch_array($nextGameID, MYSQLI_ASSOC))
- {
- //echo $row['max'];
- $gameID = $row['max'] + 1;
- echo 'Game ID: ' . $gameID . '<br/>';
- }
- $nextStatID =$conn->query("SELECT MAX(stat_id) `max` FROM game_stats");
- if (!$nextStatID) die($conn->error);
- while($row=mysqli_fetch_array($nextStatID, MYSQLI_ASSOC))
- {
- //echo $row['max'];
- $statID = $row['max'] + 1;
- echo 'Stat ID: ' . $statID. '<br/>';
- }
- //print_r($_FILES["upload"]);
- //echo inputCompID
- $compID = $_POST['inputCompID'];
- // Count # of uploaded files in array
- $total = count($_FILES['upload']['name']);
- // Loop through each file
- for($i=0; $i<$total; $i++) {
- $extension = end(explode(".", $_FILES["upload"]["name"][$i]));
- if (($_FILES["upload"]["size"][$i] < 200000)
- && in_array($extension, $allowedExts)) {
- if ($_FILES["upload"]["error"][$i] > 0)
- {
- echo "Return Code: " . $_FILES["upload"]["error"][$i] . "<br />";
- }
- else
- {
- $path = $_FILES["upload"]["name"][$i];
- $pathInfo = pathinfo($path);
- //print_r($pathInfo);
- echo "Upload: " . $_FILES["upload"]["name"][$i] . "<br />";
- echo "Type: " . $_FILES["upload"]["type"][$i] . "<br />";
- echo "Size: " . ($_FILES["upload"]["size"][$i] / 1024) . " Kb<br />";
- echo "Temp file: " . $_FILES["upload"]["tmp_name"][$i] . "<br />";
- $loc = "competitions/$compID/". $pathInfo['filename'] ."/". $_FILES["upload"]["name"][$i];
- if (file_exists("competitions/$compID/". $pathInfo['filename'] ."/" . $_FILES["upload"]["name"][$i]))
- {
- echo $_FILES["upload"]["name"][$i] . " already exists. ";
- }
- else
- {
- // Check if directory exists if not create it
- if(!is_dir("competitions/$compID/". $pathInfo['filename'] ."/")) {
- mkdir("competitions/$compID/". $pathInfo['filename'] ."/", 0777, true);
- }
- move_uploaded_file($_FILES["upload"]["tmp_name"][$i],
- "competitions/$compID/". $pathInfo['filename'] ."/". $_FILES["upload"]["name"][$i]);
- echo "Stored in: " . "competitions/$compID/". $pathInfo['filename'] ."/". $_FILES["upload"]["name"][$i];
- }
- $team1Players = '';
- $team2Players = '';
- require_once 'Classes/PHPExcel/IOFactory.php';
- $objReader = PHPExcel_IOFactory::createReader('Excel2007');
- $objPHPExcel = $objReader->load($loc);
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
- $objWriter->setDelimiter(";");
- $objWriter->setEnclosure("");
- $index = 0;
- foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
- $objPHPExcel->setActiveSheetIndex($index);
- $objWorksheet = $objPHPExcel->getActiveSheet();
- //objWorksheet = $objPHPExcel->getActiveSheet();
- /* echo '<table border=1>' . "\n";
- foreach ($objWorksheet->getRowIterator() as $row) {
- echo '<tr>' . "\n";
- $cellIterator = $row->getCellIterator();
- $cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
- // even if it is not set.
- // By default, only cells
- // that are set will be
- // iterated.
- foreach ($cellIterator as $cell) {
- echo '<td>' . $cell->getValue() . '</td>' . "\n";
- }
- echo '</tr>' . "\n";
- }
- echo '</table>' . "\n";*/
- // write out each worksheet to it's name with CSV extension
- $title = str_replace(array("-"," "), "-", $worksheet->getTitle());
- $outFile = "competitions/$compID/". $pathInfo['filename'] ."/". $title . '-' . $pathInfo['filename'] . ".csv";
- $objWriter->setSheetIndex($index);
- $objWriter->save($outFile);
- //$handle = fopen("competitions/". $pathInfo['filename'] ."/". $title . '-' . $pathInfo['filename'] . ".csv", "r");
- //while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
- //$import="INSERT into tablename(item1,item2,item3,item4,item5) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
- //print_r($data);
- //mysql_query($import) or die(mysql_error());
- //}
- //fclose($handle);
- $row = 1;
- if (($handle = fopen("competitions/$compID/". $pathInfo['filename'] ."/". $title . '-' . $pathInfo['filename'] . ".csv", "r")) !== FALSE) {
- while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
- $num = count($data);
- //print_r($data);
- if($title == 'General') {
- //echo "<p> $num fields in line $row: <br /></p>\n";
- //print_r($data);
- if($row != 1) {
- $map = $data[3];
- $team1 = $data[9];
- $team2 = $data[10];
- $team1Score = $data[11];
- $team2Score = $data[12];
- $score = $data[11] . '-' . $data[12];
- echo '<br/><br/>';
- echo 'General Sheet:<br/>';
- echo 'Map: ' . $map . '<br/>';
- echo 'Team 1: ' . $team1. '<br/>';
- echo 'Team 2: ' . $team2. '<br/>';
- echo 'Score: ' . $score. '<br/>';
- echo '<br/><br/>';
- if($team1Score > $team2Score) {
- $winningteam = 'team1';
- $losingTeam = 'team2';
- } else {
- $winningteam = 'team2';
- $losingTeam = 'team1';
- }
- }
- } elseif($title == 'Players') {
- //print_r($data);
- if($row != 1) {
- if($data[3] == $team1) {
- $team1Players .= $data[0] . ', ';
- } elseif($data[3] == $team2) {
- $team2Players .= $data[0] . ', ';
- }
- }
- }
- $row++;
- }
- if($winningteam == 'team1') {
- $winningTeamLineup = $team1Players;
- $losingTeamLineup = $team2Players;
- } elseif($winningteam == 'team2') {
- $winningTeamLineup = $team2Players;
- $losingTeamLineup = $team1Players;
- }
- fclose($handle);
- }
- $index++;
- }
- }
- } else {
- echo "Invalid file";
- }
- }
- $sql = "INSERT INTO game (game_id, comp_id, map_name, start_time, end_time, finished, reason_not_finished, game_score, game_format, winning_teammembers, losing_teammembers)
- VALUES ($gameID, $compID, '$map', 0, 0, 1, null, '$score', null, '$winningTeamLineup', '$losingTeamLineup')";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- /*$sql = "INSERT INTO game_stas (stat_id, game_id, steam_id, alias, FHteam, SHteam, rating, kills, deaths, 1k, 2k, 3k, 4k, ace, damage, rounds, shots, hits, accuracy_percent, headshots, headshot_percentage, kdr, fpr, dpr, clutchwon, clutch_percent, lastalive_percent)
- VALUES ($nextID, $gameID, steamid, alias, FHteam, SHteam, rating, kills, deaths, 1k, 2k, 3k, 4k, ace, damage, rounds, shots, hits, accuracy_percent, headshots, headshot_percentage, kdr, fpr, dpr, clutchwon, clutch_percent, lastalive_percent)";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }*/
- // Loop through each file
- for($i=0; $i<$total; $i++) {
- $extension = end(explode(".", $_FILES["upload"]["name"][$i]));
- if (($_FILES["upload"]["size"][$i] < 200000)
- && in_array($extension, $allowedExts)) {
- if ($_FILES["upload"]["error"][$i] > 0)
- {
- echo "Return Code: " . $_FILES["upload"]["error"][$i] . "<br />";
- }
- else
- {
- $path = $_FILES["upload"]["name"][$i];
- $pathInfo = pathinfo($path);
- $loc = "competitions/$compID/". $pathInfo['filename'] ."/". $_FILES["upload"]["name"][$i];
- require_once 'Classes/PHPExcel/IOFactory.php';
- $objReader = PHPExcel_IOFactory::createReader('Excel2007');
- $objPHPExcel = $objReader->load($loc);
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
- $objWriter->setDelimiter(";");
- $objWriter->setEnclosure("");
- $index = 0;
- foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
- $objPHPExcel->setActiveSheetIndex($index);
- $objWorksheet = $objPHPExcel->getActiveSheet();
- // write out each worksheet to it's name with CSV extension
- $title = str_replace(array("-"," "), "-", $worksheet->getTitle());
- $outFile = "competitions/$compID/". $pathInfo['filename'] ."/". $title . '-' . $pathInfo['filename'] . ".csv";
- $objWriter->setSheetIndex($index);
- $objWriter->save($outFile);
- $row = 1;
- if (($handle = fopen("competitions/$compID/". $pathInfo['filename'] ."/". $title . '-' . $pathInfo['filename'] . ".csv", "r")) !== FALSE) {
- while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
- $num = count($data);
- //print_r($data);
- if($title == 'Players') {
- //print_r($data);
- if($row != 1) {
- $alias = $data[0];
- $steamid = $data[1];
- //echo 'FH Team'. '?'.'<br/>';
- //echo 'SH Team: '. '?'.'<br/>';
- $rating = $data[16];
- $kills = $data[4];
- $deaths = $data[5];
- $onekill = $data[27];
- $twokill = $data[26];
- $threekill = $data[25];
- $fourkill = $data[24];
- $ace = $data[23];
- $damageTotal = $data[21] + $data[22];
- //echo 'Rounds: '. '?'.'<br/>';
- //echo 'Shots: '. '?'.'<br/>';
- //echo 'Shots: '. '?'.'<br/>';
- //echo 'Accuracy Percent: '. '?'.'<br/>';
- $headshots = $data[8];
- $headshotPercent = $data[9];
- $kdr = $data[7];
- $fpr = $data[17];
- $dpr = $data[19];
- $clutchwon = $data[28] + $data[29] + $data[30] + $data[31] + $data[32];
- //echo 'Clutch Percent: '. '?'.'<br/>';
- //echo 'Last Alive Percent '. '?'.'<br/>';
- echo 'Alias: '. $alias .'<br/>';
- echo 'Steam ID'. $steamid .'<br/>';
- echo 'FH Team'. '?'.'<br/>';
- echo 'SH Team: '. '?'.'<br/>';
- echo 'Rating: '. $rating .'<br/>';
- echo 'Kills: '. $kills .'<br/>';
- echo 'Deaths: '. $deaths .'<br/>';
- echo '1k: '. $onekill .'<br/>';
- echo '2k: '. $twokill .'<br/>';
- echo '3k: '. $threekill .'<br/>';
- echo '4k: '. $fourkill .'<br/>';
- echo 'Ace: '. $ace .'<br/>';
- echo 'Damage: '. $damageTotal .'<br/>';
- echo 'Rounds: '. '?'.'<br/>';
- echo 'Shots: '. '?'.'<br/>';
- echo 'Shots: '. '?'.'<br/>';
- echo 'Accuracy Percent: '. '?'.'<br/>';
- echo 'Headshots: '. $headshots .'<br/>';
- echo 'Headshot Percent: '. $headshotPercent .'<br/>';
- echo 'KDR: '. $kdr .'<br/>';
- echo 'FPR: '. $fpr .'<br/>';
- echo 'DPR: '. $dpr .'<br/>';
- echo 'Clutchwon: '. $clutchwon .'<br/>';
- echo 'Clutch Percent: '. '?'.'<br/>';
- echo 'Last Alive Percent '. '?'.'<br/>';
- echo $statID++;
- //stat_id, game_id, steam_id, alias, FHteam, SHteam, rating, kills, deaths, 1k, 2k, 3k, 4k, ace, damage, rounds, shots, hits, accuracy_percent, headshots, headshot_percentage, kdr, fpr, dpr, clutchwon, clutch_percent, lastalive_percent
- $sql = "INSERT INTO game_stats (stat_id, game_id, steam_id, alias, FHteam, SHteam, rating, kills, deaths, 1k, 2k, 3k, 4k, ace, damage, rounds, shots, hits, accuracy_percent, headshots, headshot_percent, kdr, fpr, dpr, clutchwon, clutch_percent, lastalive_percent)
- VALUES ($statID, $gameID, '$steamid', '$alias', 'FHteam', 'SHteam', $rating, $kills, $deaths, $onekill, $twokill, $threekill, $fourkill, $ace, $damageTotal, 'rounds', 'shots', 'hits', 'accuracy_percent', $headshots, $headshotPercent, $kdr, $fpr, $dpr, $clutchwon, 'clutch_percent', 'lastalive_percent')";
- if ($conn->query($sql) === TRUE) {
- echo "New record created successfully";
- } else {
- echo "Error: " . $sql . "<br>" . $conn->error;
- }
- }
- }
- $row++;
- }
- fclose($handle);
- }
- $index++;
- }
- }
- } else {
- echo "Invalid file";
- }
- }
- $conn->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement