HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/content-sp/work-sp/trace_image.php
<?php

error_reporting(E_ALL);
ini_set('display_errors', 'on');

include_once('config.php');
include_once('functions.php');

$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$root_link = $protocol . $_SERVER['HTTP_HOST'] . '/';

$master_id = $_REQUEST['master_id'];
$limit = ($_REQUEST['limit'] != '') ? $_REQUEST['limit'] : 1;
if ($limit == 1) {
    $from = $limit;
    $to = 100;
} else {
    $from = ($limit * 100) + 1;
    $to = 100;
}
$mType = 'oly';


$getQuesQuery = "select question_id, subject_id, topic_id, sub_topic_id, question_instruction, question_statement, option_1, option_2, option_3, option_4, option_5, question_solution from `csp_sp_question` where master_id='$master_id' AND (question_instruction like '%img%' or question_statement like '%img%' or option_1 like '%img%' or option_2 like '%img%' or option_3 like '%img%' or option_4 like '%img%' or option_5 like '%img%' or question_solution like '%img%') order by question_id limit $from, $to";
$queryCon = $conn->query($getQuesQuery);

include 'str_replace_type.php';


function checkMissing($srcUrl)
{
    $reqUrl = $_SERVER['REQUEST_URI'];
    if(strpos($srcUrl, 'content.grapossconnect.com')){
        $findUrl = $srcUrl;
    } else {
        $findUrl = "https://content.grapossconnect.com/" . $srcUrl;
    }
    $headers = @get_headers($findUrl);
    if ($headers && strpos($headers[0], '404')) {
        // $myfile = fopen("missingImage.txt", "a");
        $reUrl = $reqUrl."====".$srcUrl."\n";
        // fwrite($myfile, $reUrl);
    }
}


?>

<table>
    <tr>
        <th>#N</th>
        <th>QId</th>
        <th>Instruction</th>
        <th>Question</th>
        <th>Option1</th>
        <th>Option2</th>
        <th>Option3</th>
        <th>Option4</th>
        <th>Option5</th>
        <th>Solution</th>
    </tr>
    <?php
    $i = 1;
    foreach ($queryCon as $ques) {
        $get_Img_Src = '/<img[^>]*src=([\'"])(?<src>.+?)\1[^>]*>/i';
        $instructions = str_replace('../', '/', $ques['question_instruction']);
        $instructions = str_replace($spaceArray, $replaceSpaceArray, $instructions);

        $question = str_replace('../', '/', $ques['question_statement']);
        $question = str_replace($spaceArray, $replaceSpaceArray, $question);

        $option1 = str_replace('../', '/', $ques['option_1']);
        $option1 = str_replace($spaceArray, $replaceSpaceArray, $option1);

        $option2 = str_replace('../', '/', $ques['option_2']);
        $option2 = str_replace($spaceArray, $replaceSpaceArray, $option2);

        if ($ques['option_3']) {
            $option3 = str_replace('../', '/', $ques['option_3']);
            $option3 = str_replace($spaceArray, $replaceSpaceArray, $option3);
        } else {
            $option3 = "";
        }

        if ($ques['option_4']) {
            $option4 = str_replace('../', '/', $ques['option_4']);
            $option4 = str_replace($spaceArray, $replaceSpaceArray, $option4);
        } else {
            $option4 = "";
        }

        if ($ques['option_5']) {
            $option5 = str_replace('../', '/', $ques['option_5']);
            $option5 = str_replace($spaceArray, $replaceSpaceArray, $option5);
        } else {
            $option5 = "";
        }

        $question_solution = str_replace('../', '/', $ques['question_solution']);
        $question_solution = str_replace($spaceArray, $replaceSpaceArray, $question_solution);

        preg_match_all($get_Img_Src, $instructions, $instrctnImgPath);
        preg_match_all($get_Img_Src, $question, $statmntImgPath);
        preg_match_all($get_Img_Src, $option1, $option1ImgPath);
        preg_match_all($get_Img_Src, $option2, $option2ImgPath);
        preg_match_all($get_Img_Src, $option3, $option3ImgPath);
        preg_match_all($get_Img_Src, $option4, $option4ImgPath);
        preg_match_all($get_Img_Src, $option5, $option5ImgPath);
        preg_match_all($get_Img_Src, $question_solution, $solutnImgPath);

    ?>
        <tr>
            <td><?php echo $i; ?></td>
            <td><?php echo $ques['question_id']; ?></td>
            <td>
                <?php
                if (!empty($instrctnImgPath['src'][0])) {
                    checkMissing($instrctnImgPath['src'][0]);
                    echo $instrctnImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $instrctnImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($statmntImgPath['src'][0])) {
                    checkMissing($statmntImgPath['src'][0]);
                    echo $statmntImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $statmntImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($option1ImgPath['src'][0])) {
                    checkMissing($option1ImgPath['src'][0]);
                    echo $option1ImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $option1ImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($option2ImgPath['src'][0])) {
                    checkMissing($option2ImgPath['src'][0]);
                    echo $option2ImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $option2ImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($option3ImgPath['src'][0])) {
                    checkMissing($option3ImgPath['src'][0]);
                    echo $option3ImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $option3ImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($option4ImgPath['src'][0])) {
                    checkMissing($option4ImgPath['src'][0]);
                    echo $option4ImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $option4ImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($option5ImgPath['src'][0])) {
                    checkMissing($option5ImgPath['src'][0]);
                    echo $option5ImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $option5ImgPath['src'][0] . '" />';
                } ?>
            </td>
            <td>
                <?php
                if (!empty($solutnImgPath['src'][0])) {
                    checkMissing($solutnImgPath['src'][0]);
                    echo $solutnImgPath['src'][0];
                    echo "<br>";
                    echo '<img src="' . $solutnImgPath['src'][0] . '" />';
                } ?>
            </td>
        </tr>
    <?php $i++;
    } ?>
</table>

<style>
    table {
        border: 1px solid #ccc;
        border-collapse: collapse;
        margin: 0;
        padding: 0;
        width: 100%;
        table-layout: fixed;
    }

    table caption {
        font-size: 1.5em;
        margin: .5em 0 .75em;
    }

    table tr {
        background-color: #f8f8f8;
        border: 1px solid #ddd;
        padding: .35em;
    }

    table th,
    table td {
        padding: .625em;
        text-align: center;
        border: 1px solid #ccc;
        word-wrap: break-word;
    }

    table th {
        font-size: .85em;
        letter-spacing: .1em;
        text-transform: uppercase;
    }

    @media screen and (max-width: 600px) {
        table {
            border: 0;
        }

        table caption {
            font-size: 1.3em;
        }

        table thead {
            border: none;
            clip: rect(0 0 0 0);
            height: 1px;
            margin: -1px;
            overflow: hidden;
            padding: 0;
            position: absolute;
            width: 1px;
        }

        table tr {
            border-bottom: 3px solid #ddd;
            display: block;
            margin-bottom: .625em;
        }

        table td {
            border-bottom: 1px solid #ddd;
            display: block;
            font-size: .8em;
            text-align: right;
        }

        table td::before {
            /*
    * aria-label has no advantage, it won't be read inside a table
    content: attr(aria-label);
    */
            content: attr(data-label);
            float: left;
            font-weight: bold;
            text-transform: uppercase;
        }

        table td:last-child {
            border-bottom: 0;
        }
    }

    /* general styling */
    body {
        font-family: "Open Sans", sans-serif;
        line-height: 1.25;
    }

    img {
        width: 100%;
    }
</style>