Sindbad~EG File Manager

Current Path : /home/beeson/public_html/WebMathXpert/
Upload File :
Current File : //home/beeson/public_html/WebMathXpert/EnterDefiniteIntegral.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';  
	}
		 session_start();
	$sessionId = session_id();  // guaranteed not to contain a pipe character
	ini_set('display_errors', 1);
	error_reporting(E_ALL);
	require("SendMessage.php");
	$RIEMANNSUMS =18;
	$TRAPEZOIDRULE=19;
	$SIMPSONSRULE=20;

?>
<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';
		font-size: 16px;
		fill: black; 
		text-align: center;
	}
	/* Ensure Arial for button and tooltip text */
	.svg-button text, .svg-button svg text, .tooltip svg text{
		font-family: 'Arial';
  }
	/* Stacking form elements vertically */
	form {
		display: flex;
		flex-direction: column;
		align-items: flex-start; /* Align items to the start of the form */
		gap: 10px; /* Add some space between each element */
	}
	#formulaPrompt {
		margin-bottom: 5px;
	}
	input[type="text"] {
		width: 300px; /* Set the width of the text input */
	}
 /* CSS to style the entry fields with a light green background */
 input[type="text"],
 input[type="number"],
 input[type="email"],
 textarea
{
   background-color: #ccffcc; /* Light green background */
   border: 1px solid #ccc; /* Optional: Border styling */
   padding: 5px; /* Optional: Padding for better spacing */
   border-radius: 4px; /* Optional: Rounded corners */
 }

 /* Style for focus state */
 input[type="text"]:focus,
 input[type="number"]:focus,
 input[type="email"]:focus,
 textarea:focus,
 select:focus {
   background-color: #b3ffb3; /* Slightly darker green when focused */
   outline: none; /* Remove default outline */
   border-color: #66cc66; /* Optional: Change border color on focus */
 }
#svgContainer, #myForm {
    display: block; /* Ensures each is on its line */
    width: 100%; /* Adjusts width to the container */
}

#svgContainer {
    margin-bottom: 5px; 
	 margin-top: 10px;
	 background-color: lightblue;
}
#EntryFields {
	    display: flex;
	    align-items: center;
	}

	.function-entry {
	    display: flex;
	    align-items: center;
	}

	#expressionID {
	    flex: 1; /* Allow input field to take up remaining space */
	}

	#arrowButton {
	    background: none;
	    border: none;
	    padding: 0;
	    margin-left: 10px; /* Add some spacing between the input and button */
	    cursor: pointer;
	}

	#arrowButton img {
		display: block;
	}
 
/* Tooltips  */  
.tooltip {
	position: absolute;
	background-color: lightyellow; 
	border: 1px solid black;
	color: black;
	padding: 5px;
	border-radius: 3px;
	white-space: nowrap;
	z-index: 1000;
	display: none; /* Hide by default */ 
	font-size: 12px; /* Change the font size */
	font-family: Arial, sans-serif; 
}

.tooltip::before {
    content: '';
    position: absolute;
    top: -8px; /* Adjust based on the size of the triangle */
    left: 0px; /* Adjust based on desired position */
    border-width: 0 5px 10px 0px; /* Create a smaller yellow triangle pointing up */
    border-style: solid; 
    border-color: transparent transparent lightyellow transparent; /* Only the bottom part is visible */
}

.hidden {
	display: none;
}
</style>
<title><?php echo($title); ?></title>
<?php 
if (isset($_POST['topicField3']))   // may have been set by ArrowButton.js 
	{ $topic = $_POST['topicField3'];   
	  // echo("topic = $topic");  // used for debugging 
		// now set the problemtype and graphtype accordingly
		switch($topic) 
			{	case  37:  // riemann_sums   
					$problemtype = 216;
					$graphtype = 18; 
					break;
				case  38:  // trapezoid_rule 
					$problemtype = 217; 
					$graphtype = 19;
					break;
				case  39:  // simpsons_rule 
					$problemtype = 218; 
					$graphtype = 20; 
					break;
			}
	}
?>
<?php
	$language = $_GET['language'];
	$windowWidth = $_GET['windowWidth'];
	$windowHeight = $_GET['windowHeight'];
	$toolbarWidth = $_GET['toolbarWidth'];  // this needs to be passed to GraphDoc.php
	$graphWidth = $windowWidth - $toolbarWidth;
	$integrand = isset($_POST['data']) ? $_POST['data'] : ''; // Capture the input after submission
	$from = isset($_POST['from']) ? $_POST['from'] : '';
	$to = isset($_POST['to']) ? $_POST['to'] : '';
	$nintervals = isset($_POST['nintervals']) ? $_POST['nintervals'] : '';
	$riemannStyle = isset($_POST['riemannStyle']) ? $_POST['riemannStyle'] : '0';
	if(isset($_POST['nintervals'])) 
		{ 
			if($topic == 37)
				{  
					$problemText= "$integrand,$from,$to,$nintervals,$riemannStyle";   
				} 
			else 
				{  
					$problemText = "$integrand,$from,$to,$nintervals";
				}
		}
	else
		$problemText= "$integrand,$from,$to";

	if ($_SERVER["REQUEST_METHOD"] === "POST") 
		{  $editflag = 0; 
			if(isset($_POST["editflagField"]))   // after the simulated Display click in presentProblem() 
				{ $editflag = 0;  
				  echo( "<script>var editflag = false;</script>");
				}
			if(isset($_POST["problemTextField"]))   // direct from the Edit button in GetProblemAsync.php
				{  // from the Edit button in GetProblemAsync.php  
					$problemText =  $_POST["problemTextField"]; 
					$editTopic = $_POST["topicField"]; 
					$editflag = 1;
					echo( "<script> var problemText = \"$problemText\"; var editTopic = $editTopic; var editflag = true;</script>");  
				} 
		}
		
?>
<script>

	// JavaScript function to validate the form for nonempty entry before submission
	// Further validation is left to the Engine, e.g. "Endpoints must be numerical"
	function validateForm(event) {
		// Get the value of the input field  
		const expression = document.forms["formulaForm"]["data"].value.trim();  
		console.log(expression); 
		const from = document.forms["formulaForm"]["from"].value.trim(); 
		const to = document.forms["formulaForm"]["to"].value.trim(); 
		const nintervals = document.forms["formulaForm"]["nintervals"].value.trim(); 
		if(expression == "" || from == "" || to == "" || nintervals == ""){ 
			// Show an alert if validation failed 
			alert(translations["<?php echo $language; ?>"]['alert6']);  // please enter an expression
			// Prevent the form from being submitted
			event.preventDefault();
			return false;
		} 	
		return true; 
	}

	// Add the validation function to the form's submit event
	document.addEventListener('DOMContentLoaded', function() {
		document.getElementById("formulaForm").addEventListener("submit", validateForm);
	});
</script>
<script>
// global variables, changeable by complexSelector, passed by POST['complexSelector'] when Display is clicked
var topic = <?php echo($topic); ?>;
var problemtype = <?php echo($problemtype); ?>;
var graphtype = <?php echo($graphtype); ?>;
</script>
</head>
<body>

<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']); ?>" 
		method="post" 
		id="formulaForm"
		autocomplete="on"
>

	<!-- Container for Function to Integrate -->
	<div>
		<svg id="topicReminder0" width="170" height="25">  
			<text x="170" y="20" text-anchor="end">Selected method: </text>
		</svg>
	   <svg id="topicReminder<?php echo($topic); ?>" width="200" height="25">  
			<text x="5" y="20"> Riemann sums</text>
		</svg>
	</div>
	<div 
	    id="EntryFields" 
	    style="display: flex; 
	           align-items: center; 
	           margin-bottom: 10px;"
	>
		<div style="width: 170px; text-align: right; margin-right: 10px;">
			<svg id="functionRiemannSums" width="170" height="25">  // same prompt for all three approximate integration topics
				<text x="170" y="20" text-anchor="end">Function to integrate:</text>
			</svg>
		</div>
		<div class="function-entry">
			<input type="text" id="<?php echo $placeholderID ?>" 
				name="data" style="width: 300px;" placeholder="y = x^3 - ax for example, or just x^3 - ax" 
				value="<?php echo htmlspecialchars($integrand); ?>"
				autofocus
			>
			<button
				id="arrowButton"
				class="svg-button"
				type="button"
				onClick="handleArrowClick(document.getElementById('<?php echo $placeholderID ?>'),graphtype,topic)"
			>
			<img src="images/drawn_bow_arrow_30px.png" alt="Arrow Icon" width="30" height="30">
			</button>
		</div>
 	</div>

    <!-- Container for 'From' Input -->
    <div style="display: flex; align-items: center; margin-bottom: 10px;">
        <label  id="from" style="width: 170px; text-align: right; margin-right: 10px;">From:</label>
        <input type="text" id="shadowfrom" name="from" style="width: 30px;" value="<?php echo htmlspecialchars($from); ?>">
    </div>

    <!-- Container for 'To' Input -->
    <div  style="display: flex; align-items: center; margin-bottom: 10px;">
        <label id="to" style="width: 170px; text-align: right; margin-right: 10px;">To:</label>
        <input type="text" id="shadowto" name="to" style="width: 30px;" value="<?php echo htmlspecialchars($to); ?>">
    </div>

	<!-- Conditional Container for 'Number of Intervals' Input -->
	<?php if ($topic == 37 || $topic == 38|| $topic == 39): ?>
		<div style="display: flex; align-items: center; margin-bottom: 10px;">
	        <label  id="nintervals" style="width: 170px; text-align: right; margin-right: 10px;">Number of intervals:</label>
	        <input type="text" id="shadownintervals" name="nintervals" style="width: 60px;" value="<?php echo htmlspecialchars($nintervals); ?>">
		</div>
	<?php endif; ?>
	<?php if ($topic == 37):   // 37 is _riemann_sums from tdefn.h  ?>
		<!-- Container for 'Style of Riemann sums' Select -->
		<div style="display: flex; align-items: center; margin-bottom: 10px;">
			<label id="riemannStyle" style="width: 170px; text-align: right; margin-right: 10px;">Style of rectangles:</label>
			<select name="riemannStyle" style="width: 100px;">
				<option value="0" <?php echo $riemannStyle == '0' ? 'selected' : ''; ?> id="styleLeft">Left</option>
				<option value="1" <?php echo $riemannStyle == '1' ? 'selected' : ''; ?> id="styleCentered">Centered</option>
				<option value="2" <?php echo $riemannStyle == '2' ? 'selected' : ''; ?> id="styleRight">Right</option>
			</select>
		</div>
	<?php endif; ?>
	 

    <!-- Submit Button -->
	<button type="submit" id="displayButton1" class="svg-button" style="background-color:transparent; border:none;">
		<svg width="800" height="30" style="position:relative; overflow:visible;" xmlns="http://www.w3.org/2000/svg">
			<rect width="80" height="30" fill="rgb(0,0,128)" />
			<text x="40" y="20" style="fill:white;" font-size="12" font-family="Arial" text-anchor="middle">Display</text>
		</svg>
	</button>
	<input type="hidden" name="topicField3" value="<?php echo($topic); ?>" id="topicField3">
	<input type="hidden" name="editflagField"  value="<?php echo($editflag); ?>" id ="editflagField">
</form>



	<!-- tooltip-container is used by Tooltips.js to put each tooltip text, one at a time, into it.  So it's empty now. -->
	<div id="tooltip-container" class = "tooltip"></div>
	<!-- put all needed tooltips here as <svg> elements.
		This pre-document file does not receive Tooltips from the Engine.  They must be written here. -->
	<svg class="tooltip" id="tooltip-displayButton1" width="300" height="30" 
		style="display:none;
		position:absolute;
		left: 0; top: 0;
		xmlns="http://www.w3.org/2000/svg" 
	>
		<text x = "0" y="16" style="font-size:14px;fill:black;stroke:none;">Display the formula in mathematical notation </text>
	</svg>

	<svg class="tooltip" id="tooltip-draw2" width="250" height="30" 
		style="display:none;
		position:absolute;
		left: 0; top: 0;
		xmlns="http://www.w3.org/2000/svg" 
	>
		<text x = "0" y="16" style="font-size:14px;fill:black;stroke:none;">Draw the graph </text>
	</svg>
	</svg>	
	<svg class="tooltip" id="tooltip-arrowButton" width="250" height="40" 
		style="display:none; position:absolute; left: 0; top: 0;"
		xmlns="http://www.w3.org/2000/svg" 
	>
		<text x = "0"  y="16" style="font-size:14px;fill:black;stroke:none;">Shoots a sample problem into</text>
		<text x = "0"  y="35" style="font-size:14px;fill:black;stroke:none;">the entry field to the left</text>
	</svg>
	 <?php
	$clientSocket = createClientSocket($serverAddress, $serverPort, $timeout);
	if ($_SERVER["REQUEST_METHOD"] === "POST" && $editflag == 0) 
		{
			$integrand = isset($_POST['data']) ? $_POST['data'] : ''; // Capture the input after submission
			$from = isset($_POST['from']) ? $_POST['from'] : '';
			$to = isset($_POST['to']) ? $_POST['to'] : '';
			$nintervals = isset($_POST['nintervals']) ? $_POST['nintervals'] : ''; 
			$riemannStyle = isset($_POST['riemannStyle']) ? $_POST['riemannStyle'] : ''; 
			$toolbarWidth = isset($_POST['toolbarWidth']) ? $_POST['toolbarWidth'] : '';
			if($topic == 37)  // _riemann_sums
				$problemText= "$integrand,$from,$to,$nintervals,$riemannStyle";
			else if($topic == 38 || $topic == 39) 
				$problemText= "$integrand,$from,$to,$nintervals";  // for TRAPEZOIDRULE and SIMPSONSRULE
			else 
				$problemText= "$integrand,$from,$to";
			
			if (empty($problemText)) 
				{
					// Display an alert using JavaScript
					echo '<script>alert("You must enter a formula to be displayed");</script>';
				} 
			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) 
								{  // graphtype is the item from mainchoi.h corresponding to problemtype from proptype.h 
									$param = "\"$problemText\"+$graphtype+$language+$graphWidth+$windowHeight";
									$response = sendMessage($clientSocket,"setupAndCheckGraph",$param);
									if ($response === false)
										{
											$errcode = socket_last_error($socket);
											$message = socket_strerror($errcode);
											echo "Socket_read error: $message<br>";
										}  
									else 
										{   
											?> 
												<div style="display:none;">
													<?php include 'ButtonDefinitions.svg'; ?>
												</div>
												<div id="svgContainer" >	
														<?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 
																		svgContainer. 
																*/  
														?>	   
												</div>	 
												<?php if(strstr($response,"termSVG")){ ?>									
													<form id="myForm" method="post" action="GraphDoc.php"> 
														<!-- the action element has no name as we don't need it posted, especially not with name "action", which causes a conflict --> 
														<input type="hidden" id="formAction" value=""> 
														<!-- The following "draw2" button could be defined by <use href="#draw"></use> as in GraphDoc.php, 
														but then we still have to set the fill to white, which is done in Javascript in GraphDoc.php.   
														So I just defined it inline here, which makes it possible to modify it independent of the Graph Toolbar -->
														<button type="submit" name="draw2" id="draw2" class="svg-button"  style="background-color:transparent; border:none;">
															<svg width="80" height="30" style="position:relative;overflow:visible;" xmlns="http://www.w3.org/2000/svg">
																<!-- Background -->
																<rect width="80" height="30" fill="rgb(0,0,128)" />
																<!-- Horizontal line -->
																<line x1="10" y1="7.5" x2="70" y2="7.5" stroke="white" stroke-width="1" />
																<!-- Vertical line -->
																<line x1="40" y1="0" x2="40" y2="15" stroke="white" stroke-width="1" />
																<!-- Cubic curve -->
																<path d="M 10 15 Q 20 -5 40 7.5 Q 60 20 70 -5" fill="none" stroke="white" stroke-width="1" />
																<!-- Text -->
																<text x="40" y="25" style="fill:white;" font-size="12" font-family="Arial" text-anchor="middle" >Draw</text>
															</svg>
														</button>
														<input type="hidden" name="widthField3" id="widthField3" value = <?php echo $graphWidth ?> > 
														<input type="hidden" name="heightField3" id="heightField3" value=<?php echo $windowHeight ?> > 
														<input type="hidden" name="toolbarwidthField" id="toolbarwidthField" value = <?php echo $toolbarWidth ?> > 
														<input type="hidden" name="language" id="language" value = <?php echo $language ?> >  
														<input type="hidden" name="topicField" value="<?php echo($topic); ?>" id="topicField2">
													</form>	 
												<?php } ?>					
											<?php 
										}
								} 
							else 
								{
									echo "Failed to connect to the MathXpert Engine: " . socket_strerror(socket_last_error()) . "<br>"; 
								}
						}
				}
		}
?>
    
<script src="TranslateEnterPages.js"></script>
<script src="Tooltips.js"></script>
<script src="MoveSvgElement.js"></script>
<script>
	function adjustFormPositionAfterSvgResizes() {
		var svgContainer = document.getElementById('svgContainer');
		var myForm = document.getElementById('myForm'); 
		if(myForm == null) 
			return;
		// Get the current height of the svgContainer 
		if(svgContainer)  // it doesn't exist until the Display form is processed
			var currentHeight = svgContainer.offsetHeight;

		// Adjust the form's margin to prevent overlap
		myForm.style.marginTop = (currentHeight + 20) + 'px'; // Adjust as needed for spacing
	}

</script>

<script>

	document.addEventListener('DOMContentLoaded', function() {
	    setLanguage('<?php echo($language); ?>');
	    moveSvgElementToContainer("parsedTerm", "svgContainer");
	    // Adjust the form position right after resizing the container
	    adjustFormPositionAfterSvgResizes();  
		 if (typeof editflag !== "undefined" && editflag) {
		 			let inputField = document.getElementById('<?php echo $placeholderID?>');  
		 			topic = editTopic;  // will get us more refined solutions maybe  
		 			presentProblem(topic, problemText, inputField, problemtype);   
		 			return; 
		 		}
	});

</script>
<script src="FetchMessage.js"></script>
<script src="arrowButton.js"> </script>
</body>
</html>


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