<?php
include("../../db.php");
header("Access-Control-Allow-Origin: * ");

$user_type = $_REQUEST['user_type'];
$login_id = $_REQUEST['login_id'];
$session = $_REQUEST['session'];
$date = date("Y-m-d");
$device_id = $_REQUEST['device_id'];

// 	$user_type=mysql_real_escape_string($user_type);
// 	$session=mysql_real_escape_string($session);
// 	$date=mysql_real_escape_string($date);	
// 	$login_id=mysql_real_escape_string($login_id);
// 	$pass=mysql_real_escape_string($pass);
// 	$device_id=mysql_real_escape_string($device_id);

$err_msg = 'Invalid Login ID or Password...!';

$pass = new password();

if ($user_type == 'student') {

    if (!empty($login_id)) {
        $arr = $db->getRow("select * from student where admissionno='" . $login_id . "' and session='" . $session . "'");

        $salt     = "CrazyassLongSALTThatMakesYourUsersPasswordVeryLong123!!312567__asdSdas";
        $pass_dec = $pass->encrypt_decrypt("decrypt", $arr['password'], $salt, "a1b2c3a1b2c3a1b2");
        $arr['password'] = $pass_dec;
        $arr['pass_dec'] = $pass_dec;

        $stu_sib = $db->getval("select sibling from student where idno='" . $arr['idno'] . "'");
        // print_r($stu_sib);
        $csvString = "$stu_sib";

        $options = explode(",", $csvString);
        $options = array_filter($options);
        if (is_array($options) && count($options) > 0) {

//print_r($options);
            foreach ($options as $val) {

                $sib_name = $db->getval("select name from student where idno='" . $val . "'");
                $mobile = $db->getval("select mobile from student where idno='" . $val . "'");
                $photo = $db->getval("select photo from student where idno='" . $val . "'");

                $admission = $db->getval("select admissionno from student where idno='" . $val . "'");
                $class = $db->getval("select class from student where idno='" . $val . "'");
                $section = $db->getval("select section from student where idno='" . $val . "'");


                $joson[] = array("name" => $sib_name, "mobile" => $mobile, "photo" => "media/photo/" . $photo, "admissionno" => $admission, "class" => $class, "section" => $section);
            }
        } else {
            $joson = "";


        }

    } else {
        $err_msg = 'Admission number is not available..!';
    }


}

if ($user_type == 'teacher') {
    $arr = $db->getRow("select * from staff where mobile='" . $login_id . "'  and session='" . $session . "'");


}


if ($user_type == 'admin') {

    $arr = $db->getRow("select * from admin where login_id='" . $login_id . "'  and session='" . $session . "'");


}


if (is_array($arr) && count($arr) > 0) {

    echo json_encode(array('status' => 1, 'msg' => 'Login Successfull..!', 'data' => $arr, 'sibling' => $joson));
    //echo "http://mis.tekari.technosofttechnology.com/media/photo/".$arr["photo"];
} else {
    echo json_encode(array('status' => 0, 'msg' => $err_msg));
}
//echo $arr["name"];	

?>