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/nclive/technc/add_latest_updates.php
<?php include 'header.php';
$user_id = $_SESSION['user_id'];
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$message = ''; ?>
<style>
  #form .form-group label.error {
    color: #FB3A3A;
    display: inline-block;
    margin: 0px 0 0px 0px;
    padding: 0;

  }

  .form-horizontal .control-label {
    text-align: left !important;
  }
</style>

<main id="main-container">
  <div class="content content-narrow">
    <div class="row">
      <div class="col-lg-12">
        <h2 class="content-heading">Add Latest Updates Entity Order</h2>
        <?php
        $curDate = date('Y-m-d H:i:s');
        $sDate = $date = date("Y-m-d", strtotime("-3 months"));
        if (isset($_REQUEST['Add'])) {
          // print_r($_REQUEST);
          $Update_exam = $db->prepare("UPDATE sp_exam SET top_display_order='0',add_by='$user_id'");
          $Update_exam->execute();

          $Update_link = $db->prepare("UPDATE sp_exam_links SET display_entity='0',update_by='$user_id'");
          $Update_link->execute();

          $exam_id = $_REQUEST['exam_id'];
          $entity = $_REQUEST['entity'];
          $order = $_REQUEST['display_entity'];
          $item_count = count($_POST['exam_id']);
          if ($item_count > 0) {
            for ($i = 0; $i < $item_count; $i++) {
              if ($order[$i] == '0') {
                $message = '<div class="alert alert-warning" role="alert">Select Display Order.</div>';
              } else {
                $updatelink2 = $db->prepare("UPDATE sp_exam_links SET display_entity='1',update_by='$user_id' where id='$entity[$i]' and exam_id='$exam_id[$i]'");
                $updatelink2->execute();

                $Updateexam = $db->prepare("UPDATE sp_exam SET top_display_order='$order[$i]', add_by='$user_id' where exam_id='$exam_id[$i]'");
                $Updateexam->execute();
                $message = '<div class="alert alert-success" role="alert">Exam Successfully Updated.</div>';
              }
            }
          }
        }
        ?>
        <?php echo $message; ?>
        <div class="block">
          <div class="block-content block-content-narrow">
            <form class="js-validation-bootstrap form-horizontal" method="post" id="form">
              <div class="form-group">
                <label class="col-md-7 control-label" for="val-select2">Select Exam</label>
                <label class="col-md-4 control-label" for="val-select2">Select Entity</label>
                <label class="col-md-1 control-label" for="val-select2">Display Order</label>
              </div>
              <?php
              
              $select_entity = $db->prepare("SELECT e.exam_id, e.exam_name, e.top_display_order FROM sp_exam e LEFT JOIN (SELECT exam_id FROM sp_exam_links where display_entity='1') el ON el.exam_id = e.exam_id order by e.top_display_order desc limit 6");
              $select_entity->execute();

              $examSql = $db->prepare("SELECT e.exam_id, e.exam_name, e.top_display_order, el.id, el.exam_id FROM sp_exam e LEFT JOIN (SELECT id, exam_id FROM sp_exam_links where display_entity='0' and update_date >= '$sDate' group by exam_id) el ON el.exam_id = e.exam_id where el.exam_id IS NOT NULL order by e.exam_id desc");
              $examSql->execute(); 
              $resultExams = $examSql->fetchAll(PDO::FETCH_ASSOC);

              while ($myrow = $select_entity->fetch(PDO::FETCH_ASSOC)) {
                $examId = $myrow['exam_id']; ?>

                <div class="form-group examDropdown">
                  <div class="col-md-7">
                    <select onchange="getval(this);" class="js-select2 form-control" id="exam_id<?php echo $myrow['exam_id']; ?>" name="exam_id[]">
                      <option value="<?php echo $myrow['exam_id']; ?>"><?php echo $myrow['exam_name']; ?></option>

                      <?php foreach($resultExams as $exx) {   ?>
                        <option value="<?php echo $exx['exam_id']; ?>"><?php echo $exx['exam_name']; ?></option>
                      <?php } ?>
                    </select>
                  </div>
                  <div class="col-md-4" class="new_class entityDropdown">
                    <span>
                      <select class="js-select2 form-control entity" name="entity[]" style="width: 100%;" id="rep_opt<?php echo $myrow['exam_id']; ?>">
                        <?php $sqlExam = $db->prepare("SELECT link.id,entity.name FROM sp_exam_links as link left join sp_exam_entity as entity on entity.id=link.entity_id where link.exam_id='$examId' order by entity.display_order asc");
                        $sqlExam->execute();
                        while ($rowExam = $sqlExam->fetch(PDO::FETCH_ASSOC)) {
                          $linked_id = $rowExam['id'];
                          $sqlSelected = $db->prepare("SELECT link.id FROM sp_exam_links as link WHERE link.display_entity='1' and link.id='$linked_id'");
                          $sqlSelected->execute();
                          $linkSelected = $sqlSelected->fetch(); ?>
                          <option value="<?php echo $rowExam['id']; ?>" <?php if ($linkSelected['id'] == $rowExam['id']) {
                                                                          echo "selected";
                                                                        } ?>><?php echo $rowExam['name']; ?></option>
                        <?php } ?>
                      </select>
                    </span>
                  </div>

                  <div class="col-md-1 entityOrder">
                    <input class="form-control" type="text" name="display_entity[]" id="display_entity" value="<?php echo $myrow['top_display_order']; ?>">
                  </div>
                </div>
              <?php } ?>

              <div class="form-group">
                <div class="col-md-4"></div>
                <div class="col-md-4">
                  <button class="btn btn-lg btn-primary" type="submit" name="Add">Add</button>
                </div>
                <div class="col-md-4"></div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</main>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script type="text/javascript">
  function getval(val) {
    var exam_id = val.value;
    var enti_box = val.id.match(/\d+/);
    var site = "get_entity_new.php?id=" + exam_id;
    jQuery.ajax({
      url: site,
      cache: false,
      dataType: "jsonp",
      jsonpCallback: 'successCallback',
      success: function(data) {
        jQuery('#rep_opt' + enti_box).empty();
        // alert("rep_opt" + enti_box);
        jQuery.each(data, function(i, row) {
          jQuery('#rep_opt' + enti_box).append(row.strMessage);
        });
      },
      error: function onError(jqXHR, errorThrown) {
        alert('Entity is not Added! ');
      }
    });
  }
</script>

<?php include 'footer.php'; ?>