stollie avatar stollie committed 33e7ece

XSLT toegevoegd.

Comments (0)

Files changed (4)

 			header( "content-type: text/xml; charset=utf-8" );
 			
 			$doc = new DOMDocument('1.0', 'utf-8');
+			$doc->preserveWhiteSpace = false;
 			$doc->formatOutput = true;
+			//creating an xslt adding processing line
+			$xslt = $doc->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="countries.xsl"');
+			//adding it to the xml
+			$doc->appendChild($xslt);
 		}
 
 		if  ( $shortcode ) {
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:template match="/">
+  <html>
+  <body>
+  <h2>Teams</h2>
+  <table border="1">
+    <tr bgcolor="#9acd32">
+      <th>Team</th>
+      <th>Group</th>
+    </tr>
+    <xsl:for-each select="countries/country">
+		<xsl:sort select="@group"/>
+    <tr>
+      <td><xsl:value-of select="@name"/></td>
+      <td><xsl:value-of select="@group"/></td>
+    </tr>
+    </xsl:for-each>
+  </table>
+  </body>
+  </html>
+</xsl:template>
+
+</xsl:stylesheet> 
 			header( "content-type: text/xml; charset=utf-8" );
 			
 			$doc = new DOMDocument('1.0', 'utf-8');
+			$doc->preserveWhiteSpace = false;
 			$doc->formatOutput = true;
+			//creating an xslt adding processing line
+			$xslt = $doc->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="matches.xsl"');
+			//adding it to the xml
+			$doc->appendChild($xslt);
 		}
 		
 		if ( $id ) {
 	
 	 break;
 	
-	
-	/* AANPASSEN */
 	case 'PUT':		
 	
 		$inputSocket = fopen("php://input", "r");
 		$stmt->bindParam(':goals_out', $goals_out , PDO::PARAM_INT, 2 );
 		$stmt->bindParam(':id', $id , PDO::PARAM_INT, 3 );
 		$stmt->execute();
+		
 		if ( $stmt->rowCount() ) {
 			header('http/1.0 201');
 			
 			header('http/1.0 500 Internal Server Error');
 		}
 	 break;
-	 
+	
+	case 'POST':
+		$inputData = $_SERVER['HTTP_USER_AGENT'];
+		// schrijf bestand.
+		$handle = fopen('logs/log.txt', 'w');
+		fwrite($handle, $inputData);
+		fclose($handle);
+	
+		if ( !empty($_POST) ) {
+			$home = $_POST['home'];
+			$out = $_POST['out'];
+			$goals_home = $_POST['goals_home'];
+			$goals_out = $_POST['goals_out'];
+
+			$stmt = $db->prepare("INSERT INTO `matches`(`home`, `out`, `goals_home`, `goals_out`) VALUES (:home, :out, :goals_home, :goals_out )");
+			$stmt->bindParam(':home', $home , PDO::PARAM_STR, 2);
+			$stmt->bindParam(':out', $out , PDO::PARAM_STR, 2);
+			$stmt->bindParam(':goals_home', $goals_home , PDO::PARAM_INT, 2);
+			$stmt->bindParam(':goals_out', $goals_out , PDO::PARAM_INT, 2 );
+
+			if ( $stmt->execute() ) {
+				header('http/1.0 201');
+				$id = $stmt->lastInsertId();
+				$get = $db->prepare("SELECT m.*, 
+										phome.name AS player_home,
+										pout.name AS player_out,
+										phome.group AS group_home,
+										pout.group AS group_out
+									FROM matches AS m 
+									LEFT JOIN countries AS phome
+										ON m.home = phome.code
+									LEFT JOIN countries AS pout
+										ON m.out = pout.code
+									WHERE m.id = :id");
+				$get->bindParam(':id', $id, PDO::PARAM_INT, 2);
+				$get->execute();
+				
+				$array = $get->fetch(PDO::FETCH_ASSOC);
+			
+				if ( $type == 'json' ) {
+					header( "content-type: application/json; charset=utf-8" );
+					// Add links
+					$array['links']['player_home'] = "http://localhost/ek-api/countries/".$array['home'].".".$type ;
+					$array['links']['group_home'] = "http://localhost/ek-api/countries/".$array['group_home'].".".$type ;
+					$array['links']['player_out'] = "http://localhost/ek-api/countries/".$array['out'].".".$type ;
+					$array['links']['group_out'] = "http://localhost/ek-api/countries/".$array['group_out'].".".$type ;
+					echo json_encode($array);
+				}
+				else {
+					header( "content-type: text/xml; charset=utf-8" );
+					
+					$doc = new DOMDocument('1.0', 'utf-8');
+					$doc->formatOutput = true;
+					
+					$match = $doc->createElement( "match" );
+					$doc->appendChild( $match );
+					$match->setAttribute('id', $array['id']);
+						$home = $doc->createElement( "player_home",  $array['player_home'] );
+						$home->setAttribute('goals', $array['goals_home']);	
+						$match->appendChild( $home );
+			
+						$out = $doc->createElement( "player_out",  $array['player_out'] );
+						$out->setAttribute('goals', $array['goals_out']);	
+						$match->appendChild( $out );
+			
+
+						$links = $doc->createElement( "links"  );
+						$match->appendChild( $links );
+						
+							$player_home = $doc->createElement( "player_home", "http://localhost/ek-api/countries/".$array['home'].".".$type  );
+							$links->appendChild( $player_home );
+							
+							$group_home = $doc->createElement( "group_home", "http://localhost/ek-api/countries/".$array['group_home'].".".$type  );
+							$links->appendChild( $group_home );
+							
+							$player_out = $doc->createElement( "player_out", "http://localhost/ek-api/countries/".$array['out'].".".$type  );
+							$links->appendChild( $player_out );
+							
+							$group_out = $doc->createElement( "group_out", "http://localhost/ek-api/countries/".$array['group_out'].".".$type  );
+							$links->appendChild( $group_out );
+					
+					echo $doc->saveXML();
+				}	
+				
+			}
+			else {
+				header('http/1.0 500 Internal Server Error');
+			}
+		}
+		else {
+			header('http/1.0 400 Bad Request');
+		}
+	 break;
+	
 	case 'HEAD':
 		header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
 		header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
+<?xml version="1.0" encoding="utf-8"?>
+<xsl:stylesheet version="1.0"
+xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:template match="/">
+  <html>
+  <body>
+  <h2>Matches</h2>
+  <table border="1">
+    <tr bgcolor="#9acd32">
+      <th>Team</th>
+      <th>Goals</th>
+      <th> - </th>
+      <th>Goals</th>
+	  <th>Team</th>
+    </tr>
+    <xsl:for-each select="matches/match">
+    <tr>
+      <td><xsl:value-of select="player_home"/></td>
+      <td><xsl:value-of select="player_home/@goals"/></td>
+	  <td> - </td>
+      <td><xsl:value-of select="player_out/@goals"/></td>
+      <td><xsl:value-of select="player_out"/></td>	  
+    </tr>
+    </xsl:for-each>
+  </table>
+  </body>
+  </html>
+</xsl:template>
+
+</xsl:stylesheet> 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.