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/nqb_masters_treeview.php
<?php

class Category
{
    static $host;
    static $user;
    static $pwd;
    static $database;
    static $btnname;
    static $site_url;
    static $s_med;
    static $t_med;
    static $masterID;
    static $masterType;
    static $SP_MASTER_STRUCTURE;
    static $SP_MEDIUM;
    static $SP_MASTER_CATEGORY;
    static $SP_QUESTION;
    static $SP_QUESTION_MEDIUM_WISE;
    /**static $SP_QUESTION_MEDIUM_WISE;
    static $SP_MASTER_TUTORIAL;***/

    /**
     * Get the child categories
     * @return array
     */
    public static function getChildCategories($sub_id)
    {
        //	echo 'getChildCat============'.$exam_category_id;
        return self::getCategories("parent_id = {$sub_id}");
    }

    ////////////////////////////////////////////////////////////

    /**
     * The top-level categories (i.e. no parent)
     * @return array
     */
    public static function getTopCategories($from_id)
    {
        $DB_HOST = Category::$host;
        $DB_USER = Category::$user;
        $DB_PASSWORD = Category::$pwd;
        $DB_DATABSE = Category::$database;

        $Link = new mysqli($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_DATABSE);
        $Link->set_charset("utf8");

        $mediumTable = Category::$SP_MEDIUM;
        $masterStructureTable = Category::$SP_MASTER_STRUCTURE;

        
        $result = $Link->query("SELECT ms.category_name,ms.sub_id,ms.master_id,ms.parent_id, m.medium_name FROM $masterStructureTable as ms inner join $mediumTable as m on ms.medium_id=m.medium_id where ms.sub_id = '$from_id' order by ms.display_order");

        $topCats = array();
        while ($category = mysqli_fetch_object($result))
            $topCats[] = $category;

        mysqli_close($Link);
        return $topCats;
    }

    /**
     * Get categories from the database.
     * @param string $where Conditions for the returned rows to meet
     * @return array
     */
    public static function getCategories($where = '')
    {
        $DB_HOST = Category::$host;
        $DB_USER = Category::$user;
        $DB_PASSWORD = Category::$pwd;
        $DB_DATABSE = Category::$database;


        $Link = new mysqli($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_DATABSE);
        $Link->set_charset("utf8");


        if ($where)
            $where = " WHERE $where";

        $mediumTable = Category::$SP_MEDIUM;
        $examCategoryTable = Category::$SP_MASTER_STRUCTURE;
        $mId = Category::$masterID;


        $result = $Link->query("SELECT e.sub_id,e.parent_id,e.category_name,e.master_id, m.medium_name FROM $examCategoryTable as e 
        						inner join $mediumTable as m on e.medium_id=m.medium_id  $where order by e.display_order");

        $categories = array();
        while ($category = mysqli_fetch_object($result)) {
        $sId = $category->sub_id;
        //$Link->query("UPDATE $examCategoryTable set master_id='$mId' where sub_id='$sId'");
            $categories[] = $category;
        }


        mysqli_close($Link);
        return $categories;
    }
}

function outputCategories($categories, $startingLevel = 0)
{
    $DB_HOST = Category::$host;
    $DB_USER = Category::$user;
    $DB_PASSWORD = Category::$pwd;
    $DB_DATABSE = Category::$database;
    $btn_name = Category::$btnname;
    $site_url = Category::$site_url;


    $Link = new mysqli($DB_HOST, $DB_USER, $DB_PASSWORD, $DB_DATABSE);
    $Link->set_charset("utf8");

    //$indent = str_repeat("    ", $startingLevel);
    echo "<ul class='listCategory'>";
    foreach ($categories as $category) {

        $mediumTable = Category::$SP_MEDIUM;
        $examCategoryTable = Category::$SP_MASTER_STRUCTURE;
        $spQuestionTable = Category::$SP_QUESTION;
        $secondaryQues = Category::$SP_QUESTION_MEDIUM_WISE;
        $masterId = $category->master_id;
        $m_type = Category::$masterType;
        $find_src = Category::$s_med;
        $find_tar = Category::$t_med;

        $result = $Link->query("select sub_id from $examCategoryTable where parent_id=$category->sub_id");
        $childExist = mysqli_num_rows($result);

        // ----------- count all questions -------
        $questionExistQuery = "SELECT count(question_id) as total_questions FROM $spQuestionTable where master_id='$masterId' and (subject_id='$category->sub_id' or topic_id='$category->sub_id' or sub_topic_id='$category->sub_id') and medium_id='$find_src'";
        $questionResultPrm = $Link->query($questionExistQuery);
        $primary = $questionResultPrm->fetch_assoc();
        // ----------- count secondary questions -------
        $questionTrans = $Link->query("SELECT count(c.question_id) as total_questions from $secondaryQues as c INNER JOIN $spQuestionTable AS st ON st.question_id=c.question_id where st.master_id='$masterId' and (st.subject_id='$category->sub_id' or st.topic_id='$category->sub_id' or st.sub_topic_id='$category->sub_id') and c.medium_id='$find_tar'");
        $secondary = $questionTrans->fetch_assoc();

        $padding = $startingLevel * 20;
        $widthLi = (100 - $startingLevel * 5);
        $eid = $category->sub_id;
        $topic = $Link->query("select parent_id from $examCategoryTable where sub_id='$eid' ");
        $row = mysqli_fetch_object($topic);
        $topicId = $row->parent_id;
        $subject = $Link->query("select parent_id from $examCategoryTable where sub_id='$topicId'");
        $row2 = mysqli_fetch_object($subject);
        $subjectId = $row2->parent_id;

        if ($childExist == 0) {
            $class = "sub_topic";
        } else {
            $class = "topic";
        }

        echo "<li style='float:left;margin: 2px;
    border:1px solid #ccc;width:" . $widthLi . "%;padding-bottom:5px;padding-top:5px;padding-left: " . $padding . "px'>";
?>
        <style>
            .listCategory {}

            .listCategory li:hover {
                background: lightgray;
            }
        </style>
        <div class="<?php echo $class; ?>" title='Topic Id (<?php echo $eid; ?>)'><?php echo $category->category_name; ?></div>
        <div style='width:7%;float:left;font-size:14px;font-weight:bold;' title='Primary Table Questions'>[<?php echo $primary['total_questions']; ?>]</div>

        <div style='width:7%;float:left;font-size:14px;font-weight:bold;' title='Secondary Table Questions'>[<?php echo $secondary['total_questions']; ?>]</div>

        <?php
        if ($childExist == 0) {
        ?>
            <!-- <div style='width:5%;float:left;font-size:14px;' title='Question Count'><?php //echo $questionCount; 
                                                                                            ?></div>  -->
            <div style='width:8%; float:left; text-align:center; cursor:pointer;' title='Question Status'>
                <a href="/work-sp/nqb_question_status_popup?tpcId=<?php echo $eid; ?>&m=<?php echo $find_src.'&mType='.$m_type; ?>" data-backdrop="static" data-id="<?php echo $eid; ?>" target="_blank">Status</a>
            </div>
            <!--//comment by ali
        <div style='width:8%; float:left; text-align:center;' title='View questions'> 
            <a href="/work-sp/nqb_question_list_category_wise.php?topic_id=<?php echo $eid; ?>" target="_blank">View Qn</a>
        </div>-->
            <div style='width:8%; float:left; text-align:center;' title='Add questions'>
                
                <a href="/work-sp/nqb_add_question.php?sub_topic_id=<?php echo $eid . '&topic_id=' . $topicId . '&subject_id=' . $subjectId . '&master_id=' . $masterId.'&mType='.$m_type ?>" target="_blank" >Add Ques</a>
            </div>
            <!--
        <div style='width:4%; float:left; text-align:center; font-weight:bold;' title='User View Hindi'> 
            <a style="text-decoration:none; color: #0050ef;" href="/work-sp/new_question_master_user_view.php?viewIn=HI&sub_topic_id=<?php echo $eid . '&topic_id=' . $topicId . '&subject_id=' . $subjectId . '&master_id=' . $masterId; ?>" target="_blank">HI</a>
        </div>
		<div style='width:4%; float:left; text-align:center; font-weight: bold;' title='User View Bengali'> 
            <a style="text-decoration:none; color: #a05000;" href="/work-sp/new_question_master_user_view.php?viewIn=BN&sub_topic_id=<?php echo $eid . '&topic_id=' . $topicId . '&subject_id=' . $subjectId . '&master_id=' . $masterId; ?>" target="_blank">BN</a>
        </div>
		<div style='width:4%; float:left; text-align:center; font-weight: bold;' title='User View Marathi'> 
            <a style="text-decoration:none; color: #a05000;" href="/work-sp/new_question_master_user_view.php?viewIn=MR&sub_topic_id=<?php echo $eid . '&topic_id=' . $topicId . '&subject_id=' . $subjectId . '&master_id=' . $masterId; ?>" target="_blank">MR</a>
        </div>-->
            <!-- <div style='width:8%; float:left; text-align: center;' title='View Tutorial'>
                <a style="text-decoration:none;cursor:pointer;" data-toggle="modal" data-target=".bs-example-modal-lg1" onclick="view_tut(<?php echo $eid; ?>,<?php echo $masterId; ?>)" target="_blank">View Tut</a>
            </div> -->
            <!--
        <div style='width:8%; float:left; text-align: center;' title='User View'> 
            <a style="text-decoration:none;" href="/work-sp/new_question_master_translate.php?sub_topic_id=<?php echo $eid . '&topic_id=' . $topicId . '&subject_id=' . $subjectId . '&master_id=' . $masterId; ?>" target="_blank">Translate</a>
        </div>-->
        <?php
        } else {
        ?>
            <div style="width:10%;float:left;">&nbsp;</div>
        <?php
        }
        ?>
        </li>

        <?php
        $category->children = Category::getChildCategories($category->sub_id);
        outputCategories($category->children, $startingLevel + 1);
        ?>

<?php
    }
    echo "</ul>";
    mysqli_close($Link);
}
?>