<?php
 	include '../../quiklrn_app/config.php';
	//include '../quiklrn_app/config.php';
?>
<!DOCTYPE html>
<html>
<head>
<style>
#customers {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#customers td, #customers th {
  border: 1px solid #ddd;
  padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #04AA6D;
  color: white;
}
</style>

    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
        <link
            href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css"
            rel="stylesheet"
            integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi"
            crossorigin="anonymous"
        >
        <script
            src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.min.js"
            integrity="sha256-+C0A5Ilqmu4QcSPxrlGpaZxJ04VjsRjKu+G82kl5UJk="
            crossorigin="anonymous"
            defer
        ></script>
        <link
            rel="stylesheet"
            href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/css/selectize.bootstrap3.min.css"
            integrity="sha256-ze/OEYGcFbPRmvCnrSeKbRTtjG4vGLHXgOqsyLFTRjg="
            crossorigin="anonymous"
        >
		<!-- DataTables -->
		<link rel="stylesheet" href="https://cdn.datatables.net/1.13.3/css/jquery.dataTables.min.css">
				<script src="https://cdn.datatables.net/1.13.3/js/jquery.dataTables.min.js"></script>

				<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>

<h1>A Fancy Table</h1>

<table id="customers">
  <tr>
    <th>Sr. No</th>
    <th>Course Name</th>
    <th>Section Name</th>
    <th>Action</th>
  </tr>
  <tr>
    <td>Alfreds Futterkiste</td>
    <td>Maria Anders</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Berglunds snabbköp</td>
    <td>Christina Berglund</td>
    <td>Sweden</td>
  </tr>
  <tr>
    <td>Centro comercial Moctezuma</td>
    <td>Francisco Chang</td>
    <td>Mexico</td>
  </tr>
  <tr>
    <td>Ernst Handel</td>
    <td>Roland Mendel</td>
    <td>Austria</td>
  </tr>
  <tr>
    <td>Island Trading</td>
    <td>Helen Bennett</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>Königlich Essen</td>
    <td>Philip Cramer</td>
    <td>Germany</td>
  </tr>
  <tr>
    <td>Laughing Bacchus Winecellars</td>
    <td>Yoshi Tannamuri</td>
    <td>Canada</td>
  </tr>
  <tr>
    <td>Magazzini Alimentari Riuniti</td>
    <td>Giovanni Rovelli</td>
    <td>Italy</td>
  </tr>
  <tr>
    <td>North/South</td>
    <td>Simon Crowther</td>
    <td>UK</td>
  </tr>
  <tr>
    <td>Paris spécialités</td>
    <td>Marie Bertrand</td>
    <td>France</td>
  </tr>
</table>

</body>
</html>

<script>
  alert('In');

        var internal_api_url = <?php echo json_encode(INTERNAL_API_URL); ?>;
        var external_api_url = <?php echo json_encode(QUIKLRN_API_URL); ?>;
        var save_record_api_url = <?php echo json_encode(INT_SAVE_RECORD); ?>;
        var update_record_api_url = <?php echo json_encode(INT_UPDATE_RECORD); ?>;
        var web_url = <?php echo json_encode(WEBURL); ?>;

        var base_url = <?php echo json_encode(BASE_URL); ?>;
        var int_url = <?php echo json_encode(INTERNAL_API_URL); ?>;
        var int_view_url = <?php  echo json_encode(INTERNAL_VIEW_URL); ?>;
        var query = window.location.search;
        var paramters = new URLSearchParams(query);
        var auth_code = paramters.get('auth_code');

        // "college_id" => $college_id,
        // "user_idno" => $user_id

        $(document).ready(function()
        {
            alert('aa');
            get_user_id(function (resp)  {
                if(resp)
                {
                    // get_college_id(function (resp2)  {
                        // get_department(function (resp3)  {
                           
                        // });
                    // });
                }

	        });
        });


        function get_user_id( callback){
            var query = window.location.search;
            var paramters = new URLSearchParams(query);
            var auth_code = paramters.get('auth_code');

            $.ajax({
                type: "GET",
                url: external_api_url+'?method=get_user_id',
                data: {auth_code: auth_code},
                success: function(resp)
                {
                    let data1 = resp.data;
                    if(data1.length == 0 && !(auth_code=='xyz')){
                        alert("Invalid Auth Code!");
                        return false;
                    }

                    if(auth_code == 'xyz')
                    {
                            additional_reports('25');
                            return;
                    }

                    let dta = { user_id : data1[0].user_id, user_type : data1[0].user_type, user_email: data1[0].email }
                    localStorage.setItem("ReqData", JSON.stringify(dta));

                    if(data1[0].user_type == '1')
                    {
                        get_students_record(data1[0].user_id);
                    }

                    if(callback){
                        //  get_college_id(auth_code);
                        window.auth = auth_code;
                        return callback(true);
                    }else{
                        alert('callback failed in get_user_id method! ');
                    }
                },
                error: function(xhr, status, error){
                console.error(xhr);
                }
            });
        }

        function get_college_id(callback){
	        $.ajax({
				type: "GET",
				url: external_api_url+'?method=get_college_id',
				data: {u_id: JSON.parse(localStorage.getItem("ReqData")).user_id},
				success: function(data)
				{
					let data1 = data.data;
					if(!(data.status))
					{
						alert('Failed');
						return false;
					}

					if (data1[0])
					{
						$("#college_id").val(data1[0].college_id);
						$("#college_name").val(data1[0].college_name);
						let localData = JSON.parse(localStorage.getItem("ReqData"));
						localData.clg_id = data1[0].college_id;
						localData.clgName = data1[0].college_name;
						localStorage.setItem("clgData", JSON.stringify(localData));
					}

					if(callback){
						callback(true);
					}else{
						alert('callback failed in get_college_id method! ');
					}
				},
				error: function(xhr, status, error){
				console.error(xhr);
				}
			});
}

        function get_department(callback)
        {
            var user_type = JSON.parse(localStorage.getItem("ReqData")).user_type;
            // alert(user_type);
            if(user_type == 6 || user_type == 9 || user_type == 1){
                if(callback){
                        return callback(true);
                }else{
                    alert('callback failed in get_department method! ');
                }
            }
            $.ajax({
                type: "GET",
                url: external_api_url+'?method=get_department',
                data: {user_type: JSON.parse(localStorage.getItem("ReqData")).user_type,
                                clg_id: JSON.parse(localStorage.getItem("clgData")).clg_id,
                                user_id: JSON.parse(localStorage.getItem("ReqData")).user_id
                    },
                success: function(data)
                {
                    let data1 = data.data;
                    if(!(data.status))
                    {
                        alert('Failed');
                        return false;
                    }
                    if(JSON.parse(localStorage.getItem("ReqData")).user_type != 5 ){

                        let localData = JSON.parse(localStorage.getItem("ReqData"));
                        localData.dept_id = data1[0].dept_id;
                        localData.dept_name = data1[0].dept_name;
                        localStorage.setItem("dept_data", JSON.stringify(localData));
                    }
                    
                    if(callback){
                        return callback(true);
                    }else{
                        alert('callback failed in get_department method! ');
                    }
                },
                error: function(xhr, status, error){
                    console.error(xhr);
                }
            });				
        }



$.ajax({
		type: "GET",
		url: int_url+'?method=getSemesterCourseSectionDetailByUser',
		data: {clg_id: JSON.parse(localStorage.getItem("clgData")).clg_id, },
		success: function(data)
		{
			let data1 = data.data;
			let sem_val = [];
			let array = data1.user_course_detail;
			var student_detail_array = [];
			for(let x=0;x<array.length;x++){
				toUpdate = {sem_no : array[x].term_batch_sem_no,
							course_name :array[x].course_name,
							section_id : array[x].section_id
						};
						student_detail_array.push(toUpdate);
			}

		 },
		error: function(xhr, status, error){
		console.error(xhr);
		}
	});
</script>

 