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.14.245.172


Current Path : /var/www/html/pgadm/js/admin/
Upload File :
Current File : /var/www/html/pgadm/js/admin/create-user.js

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

function loadCreateUser() {
  var deggrp = $("#deggrp").val();

  var datastring = "&deggrp=" + deggrp;
  //alert(datastring);

  $.ajax({
    type: "POST",
    url: $host_url + "loadDegree",
    async: false,
    success: function(response) {
      var { error_code, data, status } = JSON.parse(response);
      if (error_code == "0") {
        $("#loadTab").load("create-user.html", function() {
          var degers = data;
          deglen = degers.length;
          var str = `<table class="table table-bordered">
                  <thead>
                    <tr class="bg-cyan">
                      <th style = "text-align: center;">Sl. No.</th>
                      <th style = "text-align: center;">Degree Code</th>
                      <th style = "text-align: center;">Degree Name</th>
                      <th style = "text-align: center;">Check Box</th>
                    </tr>
                  </thead>
                  <tbody>`;
          for (var i = 0; i < degers.length; i++) {
            str += `<tr>
            <td style = 'text-align: center;'>${i   +   1}</td>
            <td style = 'text-align: center;'>${degers[i]["fdegree"]}</td>
            <td>${degers[i]["fdescpn"]}</td>
            <td style="text-align:center">&nbsp; &nbsp;<input onChange="box(this)" type="checkbox" id="${i}_deg" value = '${
              
              
              degers[i]["fdegree"]
            
            
            }' autocomplete="off"/>
            <label for="${i}_deg" style="font-size:10px !important;">&nbsp;</label>
            </td>
          </tr>`;
          }
          $("#degtable").html(str);
        });
      } else {
        alert("Please try after some time");
        return;
      }
    }
  });
}

var checkedValue = [];
function box(obj) {
  if ($(obj).is(":checked")) {
    checkedValue.push($(obj).val());
  } else {
    if ((index = checkedValue.indexOf($(obj).val())) !== -1) {
      checkedValue.splice(index, 1);
    }
  }
}
$(function() {
  $("input[type=checkbox]").bind("click");
});

function createUser() {
  var usrname = $("#username").val();
  var password = $("#password").val();
  var mob = $("#mob").val();
  var name = $("#name").val();

  var chkval = checkedValue.join("*");
  checkedValue = [];

  if (usrname == "") {
    alert("Fill user Name");
    return;
  }

  if (mob == "") {
    alert("Fill Mobile No.");
    return;
  }

  if (name == "") {
    alert("Fill user full name");
    return;
  }

  if ($("#screen").val() == "add") {
    if (password == "") {
      alert("Fill password");
      return;
    }
  }

  var datastring =
    "&usrname=" +
    usrname +
    "&password=" +
    encodeURIComponent(password) +
    "&mob=" +
    mob +
    "&name=" +
    name +
    "&checkedValue=" +
    chkval +
    "&screen=" +
    $("#screen").val();
  $.ajax({
    type: "POST",
    url: $host_url + "createUser",
    data: datastring,
    success: function($responce) {
      $responce = eval("(" + $responce + ")");
      if ($responce.error_code == "0") {
        alert("Updated Successfullyy");
        loadCreateUser();
      } else {
        alert("Error While creting user");
      }
    }
  });
}

function loadDegree() {
  $.ajax({
    type: "POST",
    url: $host_url + "loadDegreeg",
    async: false,
    success: function(response) {
      var { error_code, data, status } = JSON.parse(response);
      if (error_code == "0") {
        var degers = data;
        deglen = degers.length;
        var str = `<table class="table table-bordered">
                  <thead>
                    <tr>
                      <th style = "text-align: center;">Sl. No.</th>
                      <th style = "text-align: center;">Degree Code</th>
                      <th style = "text-align: center;">Degree Name</th>
                      <th style = "text-align: center;">Check Box</th>
                    </tr>
                  </thead>
                  <tbody>`;
        for (var i = 1; i < degers.length; i++) {
          str += `<tr>
            <td style = 'text-align: center;'>${i}</td>
            <td style = 'text-align: center;'>${degers[i]["fdegree"]}</td>
            <td>${degers[i]["fdescpn"]}</td>
            <td>&nbsp; &nbsp;<input onChange="box(this)"  type="checkbox" id="${i}_deg" value = '${
            degers[i]["fdegree"]
          }' autocomplete="off"/>
            <label for="${i}_deg" style="font-size:10px !important;">&nbsp;</label>
            </td>
          </tr>`;
        }
        $("#degtable").html(str);
      } else {
        alert("Please try after some time");
        return;
      }
    }
  });
}

function loadedit() {
  $("#edit").show();
  $("#add").hide();
  $("#edittable").show();
  var datastring = "";
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "loadusers",
    data: datastring,
    success: function(response) {
      var { error_code, data, status } = JSON.parse(response);
      if (error_code == "0") {
        var users = data;

        var str = `<table class="table table-bordered table-hover" style="width:90%">
                  <thead>
                    <tr class="bg-cyan">
                      <th style = "text-align: center;">Sl. No.</th>
                      <th style = "text-align: center;">User Name</th>
                      <th style = "text-align: center;">Mobile No.</th>
                      <th style = "text-align: center;">Edit</th>
                      <th style = "text-align: center;">Delete</th>
                    </tr>
                  </thead>
                  <tbody>`;
        for (var i = 0; i < users.length; i++) {
          str += `<tr>
            <td style = 'text-align: center;'>${i + 1}</td>
            <td>${users[i]["name"]}</td>
            <td style = 'text-align: center;'>${users[i]["mob"]}</td>
            <td style = 'text-align: center;'>
            <button
            type="button"
            class="btn btn-primary waves-effect m-l-5"
            onclick="editUser('${users[i]["mob"]}','${users[i]["fdegree"]}','${
            users[i]["name"]
          }','${users[i]["fusername"]}')">
            Edit
            </button>
            </td>
            </td>
            <td style = 'text-align: center;'>
            <button
            type="button"
            class="btn btn-primary waves-effect m-l-5"
            onclick="deleteUser('${users[i]["mob"]}')"
          >
            Delete
          </button>
            </td>
          </tr>`;
        }
        $("#edittable").html(str);
      } else {
        alert("Please try after some time");
        return;
      }
    }
  });
}

function editUser(mob, degrees, name, username) {
  // loadCreateUser();
  $("#loadTab").load("create-user.html", function() {
    $("#edit").hide();
    $("#add").show();

    $.ajax({
      type: "POST",
      async: false,
      url: $host_url + "loadDegree",
      success: function(response) {
        var { error_code, data, status } = JSON.parse(response);
        console.log(data);
        var serv_arr = data;
        deglen = serv_arr.length;

        $("#name").val(name);
        $("#username").val(username);
        $("#mob").val(mob);
        $("#screen").val("edit");
        document.getElementById("password").disabled = true;
        document.getElementById("mob").disabled = true;
        loadDegree();
        for (var i = 1; i < deglen; i++) {
          var n = degrees.includes($(`#${i}_deg`).val() + "*");
          if (n) {
            document.getElementById(`${i}_deg`).checked = true;
            checkedValue.push($(`#${i}_deg`).val());
          }
        }
      }
    });
  });
}
function deleteUser(mob) {
  $.ajax({
    type: "POST",
    url: $host_url + "deleteUser",
    data: "mob=" + mob,
    success: function($responce) {
      $responce = eval("(" + $responce + ")");
      if ($responce.error_code == "0") {
        alert("Updated Successfullyy");
        loadCreateUser();
      } else {
        alert("Error While creting user");
      }
    }
  });
}

function logout() {
  $.ajax({
    type: "POST",
    async: false,
    url: $host_url + "logout"
  });
  window.location.href = "index.html";
}