0xV3NOMx
Linux ip-172-26-7-228 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64



Your IP : 3.138.178.162


Current Path : /var/www/html/pget/js/pg/
Upload File :
Current File : //var/www/html/pget/js/pg/option-entry.js

// var $host_url1 =
//   "http://" +
//   window.location.host +
//   "/" +
//   window.location.pathname.split("/")[1] +
// 	"/app.php?a=";

var gdata = [];
function loadOptionEntry() {
  var today = new Date();
  var startDate = new Date(2020, 08, 26);
  var endDate = new Date(2020, 08, 25);
  console.log(startDate, endDate, today);
  // console.log(fappno);
  if (today < startDate) {
    console.log("early", today, startDate);
    // alert("t is big");
    swal({
      title: `Dates are not enabled by University`,
      html: true,
      showCancelButton: false,
      confirmButtonColor: "#5495ff",
      confirmButtonText: "OK",
      closeOnConfirm: false
    });
    return;
  } else {
    console.log("eligible", today, startDate);
    // alert("start is big");

    $.ajax({
      type: "POST",
      async: false,
      url: $host_url + "getOptionEntryDet",
      success: response => {
        var { error_code, data, status } = JSON.parse(response);
        console.log(data);
        if (error_code == 0) {
          $("#loadTab").load("option-entry.html", function() {
            console.log(data);
            var priority = data.priority;
            gdata = data.optent;
            data = data.optent;
            var degrees = [];

            for (let el of data) {
              let fdegree = degrees.filter(item => item.fdegree == el.fdegree);

              if (fdegree.length == 0) {
                degrees.push(el);
              }
            }
            console.log(degrees);
            var deg_opt = `<option value="">--Select Degree--</option>`;
            for (let deg of degrees) {
              deg_opt += `<option value="${deg.fdegree}">${deg.degree}</option>`;
            }

            var html = "";
            for (let i = 0; i < 15; i++) {
              html += `<tr> 
						<td style="padding: 0px"> 
						<select name='degree' onchange="getColleges(this, ${i})" id="degree_${i}"
						class="form-line form-control" style="font-size: 16px;">
							${deg_opt}
						</select>
						</td>
						<td style="padding: 0px"> 
						<select name='college'  id="college_${i}"
						class="form-line form-control" style="font-size: 16px;">
							<option value="">--Select college--</option>
						</select>
						</td>
						<td style="padding: 0px"> 
							<input type="text" id='fproiority_${i}' class="form-line form-control" name="priority" 
							style="text-align: center;"
							placeholder="Priotity" minlength="1" 
							maxlength="2" onkeypress="return acceptNumbersOnlyForModule(event);"/>
						</td>
					</tr>`;
            }

            $("#options").html(html);
            console.log(priority);
            for (var i = 0; i < priority.length; i++) {
              $(`#degree_${i}`).val(priority[i]["fdegree"]);
              getCollegesPri(priority[i]["fdegree"], i);
              $(`#college_${i}`).val(priority[i]["fcollcode"]);
              $(`#fproiority_${i}`).val(priority[i]["fpriority"]);
            }
          });
        }
      }
    });
  }
}

function getCollegesPri(degree, i) {
  var college = gdata.filter(item => item.fdegree == degree);

  var coll_opt = `<option value="">--Select College--</option>`;
  for (let coll of college) {
    coll_opt += `<option value="${coll.fcollcode}">${coll.college}</option>`;
  }
  console.log(coll_opt);
  $("#college_" + i).html(coll_opt);
}

function getColleges(el, i) {
  var college = gdata.filter(item => item.fdegree == $(el).val());

  var coll_opt = `<option value="">--Select College--</option>`;
  for (let coll of college) {
    coll_opt += `<option value="${coll.fcollcode}">${coll.college}</option>`;
  }
  console.log(coll_opt);
  $("#college_" + i).html(coll_opt);
}

function saveOptionEntry() {
  //   login();
  var prefernces = [];
  $("#options tr").each(function() {
    var td = $(this).find("td");
    if (
      $(td)
        .find("select[name=degree]")
        .val() == "" &&
      $(td)
        .find("select[name=college]")
        .val() != "" &&
      $(td)
        .find("input[name=priority]")
        .val() != ""
    ) {
      swal({
        title: `Select Degree.`,
        html: true,
        showCancelButton: false,
        warning: true,
        confirmButtonColor: "#5495ff",
        confirmButtonText: "OK",
        closeOnConfirm: false
      });
      return;
    }
    if (
      $(td)
        .find("select[name=degree]")
        .val() != "" &&
      $(td)
        .find("select[name=college]")
        .val() == "" &&
      $(td)
        .find("input[name=priority]")
        .val() != ""
    ) {
      swal({
        title: `Select College.`,
        html: true,
        showCancelButton: false,
        warning: true,
        confirmButtonColor: "#5495ff",
        confirmButtonText: "OK",
        closeOnConfirm: false
      });
      return;
    }
    if (
      $(td)
        .find("select[name=degree]")
        .val() != "" &&
      $(td)
        .find("select[name=college]")
        .val() != "" &&
      $(td)
        .find("input[name=priority]")
        .val() == ""
    ) {
      swal({
        title: `Select Priority`,
        html: true,
        showCancelButton: false,
        warning: true,
        confirmButtonColor: "#5495ff",
        confirmButtonText: "OK",
        closeOnConfirm: false
      });
      return;
    }
    if (
      $(td)
        .find("select[name=degree]")
        .val() != "" &&
      $(td)
        .find("select[name=college]")
        .val() != "" &&
      $(td)
        .find("input[name=priority]")
        .val() != ""
    ) {
      var option = {
        degree: $(td)
          .find("select[name=degree]")
          .val(),
        college: $(td)
          .find("select[name=college]")
          .val(),
        priority: $(td)
          .find("input[name=priority]")
          .val()
      };

      for (opt of prefernces) {
        if (opt.degree == option.degree && opt.college == option.college) {
          swal({
            title: `You have selected same degree and college multiple times <br> Degree - ${option.degree}, College - ${opt.college}`,
            html: true,
            showCancelButton: false,
            warning: true,
            confirmButtonColor: "#5495ff",
            confirmButtonText: "OK",
            closeOnConfirm: false
          });
          return;
        }
      }

      for (opt of prefernces) {
        //   console.log()
        if (parseInt(opt.priority) == parseInt(option.priority)) {
          swal({
            title: `Duplicate priority not allowed.`,
            html: true,
            showCancelButton: false,
            warning: true,
            confirmButtonColor: "#5495ff",
            confirmButtonText: "OK",
            closeOnConfirm: false
          });
          return;
        }
      }

      prefernces.push(option);
    }
  });
  if (prefernces.length == 0) {
    swal({
      title: `Enter atleast one preference.`,
      html: true,
      showCancelButton: false,
      warning: true,
      confirmButtonColor: "#5495ff",
      confirmButtonText: "OK",
      closeOnConfirm: false
    });
    return;
  }
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "saveOptionEntryDet",
    data: "options=" + JSON.stringify(prefernces),
    success: response => {
      var { error_code, data, status } = JSON.parse(response);
      swal({
        title: data.msg,
        html: true,
        showCancelButton: false,
        warning: true,
        confirmButtonColor: "#5495ff",
        confirmButtonText: "OK",
        closeOnConfirm: false
      });
      if (error_code == 0) {
        makepayment(gAppNo, "026");
      }
    }
  });
}