<?php
include("../../db.php");
// header("Access-Control-Allow-Origin: * ");
header('Content-Type: application/json');

$id = $_REQUEST['admin_id'];
$session = $_REQUEST['session'];

// $admin_id = mysql_real_escape_string($id);
// $session = mysql_real_escape_string($session);

$arrayData = array();

if (isset($_GET[admin_id]) && isset($_GET[session])) {
    $adminRole = $db->getVal("select role_id from admin where id=$id and session='$session' ");
    // echo $adminRole;
    // print_r($adminRole);
    if ($adminRole > 0) {
        $assignedRoles = $db->getRows("SELECT * from admin_privilages where role_id=$adminRole and a=1 and school_id=1 ");
        if (is_array($assignedRoles) && count($assignedRoles) > 0) {

            foreach ($assignedRoles as $roles) {
                array_push($arrayData, $roles[page_name]);
            }

        }

        //get app color
        $app_color = $db->getVal("select app_theme_color from tbl_info where id='1'");

        $school_message = $db->getVal("select value from settings where field='extra_footer'");


        echo json_encode(array('status' => 1, 'data' => $arrayData, 'app_theme_color' => $app_color, 'school_message' => $school_message, 'school_info' => getSchoolInfo($db, $session)));

    } else {
        echo json_encode(array('status' => 0, 'data' => 'No data Found..!'));
    }

}

function getSchoolInfo($db, $session){

    $school_id = 1;

    $student = (int)$db->getVal("select count(idno) from student where school_id='".$school_id."' and session='".$session."' and issue_TC=0 and status=1");
    $staff   = (int)$db->getVal("select count(idno) from staff where status=1 and school_id='".$school_id."' and session='".$session."' ");
    $bus     = (int)$db->getVal("select count(idno) from student where school_id='".$school_id."' and session='".$session."' and issue_TC=0 and status=1 and bus!=''");
    $hostel  = (int)$db->getVal("select count(s.idno) from hostelinstallment as h,student as s where s.school_id='".$school_id."' and s.session='".$session."' and s.idno=h.idno and s.issue_TC=0 and s.status=1");
    $enquiry = (int)$db->getVal("select count(idno) from enquiry where school_id='".$school_id."' and session='".$session."' and status=1");
    //$sms     = (int)$db->getVal("select count(id) from sms where school_id='".$school_id."' and session='".$session."'");

    //return "Student : $student  Staff : $staff  Bus : $bus  Hostel : $hostel  Enquiry : $enquiry  SMS : $sms";
    return "Student : $student  Staff : $staff  Bus : $bus  Hostel : $hostel  Enquiry : $enquiry";

}