Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:06

0001 <?php
0002 require_once('./configurations.php');
0003 
0004 $servername = $FEconfig['dbhost'];
0005 $username = $FEconfig['dbuser'];
0006 $password = $FEconfig['dbpass'];
0007 $dbname = $FEconfig['dbname'];
0008 
0009 if (array_key_exists('UseChunkedImages', $FEconfig)) {
0010     if ($FEconfig['UseChunkedImages'] == "false") {
0011         $IsChunked = false;
0012     } 
0013 }
0014 
0015 // Create connection
0016 $conn = mysqli_connect($servername, $username, $password, $dbname);
0017 // Check connection
0018 if (!$conn) {
0019     die("Connection failed: " . mysqli_connect_error());
0020 }
0021 
0022 // pass the plot name as a url parameter, allow list of plot names
0023 $plotName = $_GET['plotName'];
0024 $IsChunked = isset($_GET['IsChunked']) ? (int) $_GET['IsChunked'] : 0;
0025 $plotNames = explode(",", $plotName);
0026 $plotNames = array_map('trim', $plotNames);
0027 
0028 // Prepare the query to get plot information
0029 $plotNamesPlaceholders = implode(',', array_fill(0, count($plotNames), '?'));
0030 $query = "
0031     SELECT Plots.*, Plot_Types.Name AS PlotTypeName, Plot_Types.Description AS Description, Plot_Types.DisplayName AS DisplayName
0032     FROM Plots
0033     JOIN Plot_Types ON Plots.Plot_Types_ID = Plot_Types.ID
0034     WHERE Plot_Types.Name IN ($plotNamesPlaceholders) and Plot_Types.IsChunked= ?
0035 ";
0036 
0037 // Prepare and bind parameters
0038 $stmt = mysqli_prepare($conn, $query);
0039 if ($stmt === false) {
0040     die("MySQL prepare statement error: " . mysqli_error($conn));
0041 }
0042 
0043 // Create a dynamic list of parameters for the prepared statement
0044 $typeStr = str_repeat('s', count($plotNames)) . 'i';
0045 $params = array_merge($plotNames, [$IsChunked]);
0046 
0047 mysqli_stmt_bind_param($stmt, $typeStr, ...$params);
0048 
0049 
0050 // Execute the query
0051 mysqli_stmt_execute($stmt);
0052 $result = mysqli_stmt_get_result($stmt);
0053 
0054 // Fetch and prepare the results
0055 $plots = [];
0056 while ($row = mysqli_fetch_assoc($result)) {
0057     $plot = [
0058         'ID' => $row['ID'],
0059         'PlotTypeID' => $row['Plot_Types_ID'],
0060         'ImagePath' => $row['RunPeriod'],
0061         'PlotTypeName' => $row['PlotTypeName'],
0062         'Description' => $row['Description'],
0063         'DisplayName' => $row['DisplayName']
0064     ];
0065     $plots[] = $plot;
0066 }
0067 
0068 // Output the results as JSON
0069 header('Content-Type: application/json');
0070 echo json_encode($plots);
0071 
0072 // Close the statement and connection
0073 mysqli_stmt_close($stmt);
0074 mysqli_close($conn);
0075 ?>