Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/ParseAndDisplay.php

<!DOCTYPE html>
<?php
$serverAddress = 'localhost'; // Adjust the server address
$serverPort = 12349; // Adjust the server port
$timeout = 300; // Connection timeout in seconds,  long enough for debugging.
$startupDelay = 5; // Delay for server startup in seconds, if server is not already running

if (!(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || 
   $_SERVER['HTTPS'] == 1) ||  
   isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&   
   $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
{
   $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   header('HTTP/1.1 301 Moved Permanently');
   header('Location: ' . $redirect);
   exit();
}
if ($_SERVER['SERVER_NAME'] == 'localhost') { 
    $serverAddress = 'localhost';  
} else {
    $serverAddress = 'mathxpert.org'; 
}
?>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, maximum-scale=1.0, user-scalable=0">
	<style>
	/* Set a global font-family rule for all text elements.  Only Times New Roman actually works well.  */
	text {
		  # font-family: 'Times New Roman'; /*, 'Cambria Math', 'STIX Two Math', 'Latin Modern Math', 'TeX Gyre Termes Math'; */
		 }
	 svg text {
	           font-family: 'Times New Roman'; 
	       }
	</style>
	<title>Parse and Display using SVG</title>
</head>
<body>
	<button onclick="LargerType()">Larger Type</button>
	<button onclick="SmallerType()">Smaller Type</button>
    <form action="ParseAndDisplay.php" method="post">
        <input type="text" name="data" placeholder="Type your formula here">
        <input type="submit" value="Typeset and Display">
    </form>
	
  
    <?php
    session_start();
    $sessionId = session_id();  // guaranteed not to contain a pipe character
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    require("SendMessage.php");
      

	$clientSocket = createClientSocket($serverAddress, $serverPort, $timeout);

	    if ($_SERVER["REQUEST_METHOD"] === "POST") 
	    {
	      $data = $_POST["data"];
		    // Check if the "data" field is empty
		  if (empty($data)) 
				{
		          // Display an alert using JavaScript
		          echo '<script>alert("You must enter a formula to be displayed");</script>'; 
		          // and don't bother speaking to the Engine
		     	} 
		  else 
		  {
	        $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);

	        if ($socket === false) 
	        {
	            echo "Socket creation failed: " . socket_strerror(socket_last_error()) . "<br>";
	        } 
			else 
	        {   
	            socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array("sec" => $timeout, "usec" => 0));
	            $result = socket_connect($socket, $serverAddress, $serverPort);

	            if ($result) 
	            {   
	                $response = sendMessage($clientSocket,"parseAndDisplay",$data);
	                if ($response === false)
	                {
	                    $errcode = socket_last_error($socket);
	                    $message = socket_strerror($errcode);
	                    echo "Socket_read error: $message<br>";
	                } else 
	                {   
						//  we want to write the SVG code in $response into the web page.  We first 
						//  include a grid for debugging purposes (so we exit php temporarily)
	                   ?>
						<svg id="mySvg2" viewBox = "0 0 320 160" xmlns="http://www3.org/2000/svg">
						    <defs>
						    <pattern id="smallGrid" width="16" height="16" patternUnits="userSpaceOnUse">
						      <path d="M 8 0 L 0 0 0 8" fill="none" stroke="gray" stroke-width="0.5"/>
						    </pattern>
						    <pattern id="grid" width="16" height="16" patternUnits="userSpaceOnUse">
						      <rect width="160" height="160" fill="url(#smallGrid)"/>
						      <path d="M 80 0 L 0 0 0 80" fill="none" stroke="gray" stroke-width="1"/>
						    </pattern>
						  </defs>    
						  <rect width="100%" height="100%" fill="url(#grid)" transform="translate(8,8)" />
						  <?php  // and now add the dynamically generated SVG
						    echo ($response);
							/*  More elaborately,  we could use Javascript to add $response to the DOM,
							    then check whether the class is parserError, and if it is, put up
								an alert with the message;  otherwise echo it as here or just add it to 
								mySVG2. But to keep this demo simple,  I didn't add that code.
							*/
							
						  ?>
						</svg>
						<?php 
	                }
	                socket_close($socket);  // because server has already closed it
	            } 
	            else 
	            {
	                echo "Failed to connect to the C program: " . socket_strerror(socket_last_error()) . "<br>";
	            }
	        }
		  }
	    }

	    ?>
    
 
	
<script>
  // Initialize the default scale factor
  var scaleFactor = 1;

  function LargerType() {
    // Check if it's already at the maximum size
    if (scaleFactor > 0.5) {
      // Decrease the scale factor by 20%
      scaleFactor -= 0.2;

      // Get the SVG element
      var svg = document.getElementById('mySvg2');

      // Dynamically change the viewBox based on the scale factor
      var newWidth = 500 * scaleFactor;
      var newHeight = 500 * scaleFactor;
      svg.setAttribute('viewBox', '0 0 ' + newWidth + ' ' + newHeight);
    }
  }

  function SmallerType() {
    // Check if it's already at the minimum size
    if (scaleFactor  <  2) {
      // Increase the scale factor by 20%
      scaleFactor += 0.2;

      // Get the SVG element
      var svg = document.getElementById('mySvg2');

      // Dynamically change the viewBox based on the scale factor
      var newWidth = 500 * scaleFactor;
      var newHeight = 500 * scaleFactor;
      svg.setAttribute('viewBox', '0 0 ' + newWidth + ' ' + newHeight);
    }
  }
</script>
</body>
</html>


 

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists