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

$idno = $_GET['idno'];
$app_token = $_GET['token'];

$last_record_id = 0;
$session = "";
$class = "";

if (isset($_GET['last_record_id'])) $last_record_id = $_GET['last_record_id'];

if (isset($_GET['session'])) $session = $_GET['session'];

if (isset($_GET['class'])) $class = $_GET['class'];


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

$is_sdl_enable = $db->getVal("select is_student_sdl_enable from tbl_info where id='1'");

$res_mode = $db->getVal("select student_result_mode from tbl_info where id='1'");

$enforce_session_change = $db->getVal("select enforce_session_change from tbl_info where id='1'");
$enforced_session = $db->getVal("select enforced_session from tbl_info where id='1'");

$data=array();


    $is_blocked =   $db->getVal("select is_blocked from student where idno='$idno' ");
    
    if($is_blocked == 1){
        $blockMod = $db->getRows("select * from student_control_block");
      if(count($blockMod)>0 && is_array($blockMod)){
        foreach($blockMod as $mods){
            $data []= $mods[module_name];
        }
    }
    }else{
        
        $allmodules = $db->getRows("select * from student_control");
    if(count($allmodules)>0 && is_array($allmodules)){
        foreach($allmodules as $module){
            $data []= $module[module_name];
        }
    }
        
    }
    
    

    $student_status = $db->getVal("select status from student where idno='$idno' ");
    
    $sdl_token = $db->getVal("select sdl_token from student where idno='$idno' ");
    
    $fee_display_type = $db->getVal("select fee_display_type from student where idno='$idno' ");
   
   
  $token_match = strcmp($sdl_token, $app_token);
  
  if($app_token=='' || $is_sdl_enable==0){ $token_match=0;  }


$loc = $db->getVal("select school_location from tbl_info where id='1'");


$medium = $db->getVal("select medium from student where idno='$idno' ");
$mediumColor = "#000000";
$houseColor = array("Christopher Columbus" => "#0000FF", "Mahatma Gandhi" => "#008000", "Albert Einstein" => "#FFC300", "Leonardo DaVinci" => "#FF0000");
if (array_key_exists($medium, $houseColor)){
    $mediumColor = $houseColor[$medium];
}

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

$sibling_count = checkSiblingCount($db, $idno);

////////
$latest_record_id = $db->getVal("select id from tbl_notification where session='$session' and (uid='$idno' or (uid = 0 AND (class = '$class' or class = ''))) order by id desc");

$is_new_notification_available = 0;

if ($latest_record_id != '' && $latest_record_id > $last_record_id) $is_new_notification_available = 1;
////////
$new_notification_count = $db->getRows("select id from tbl_notification where session='$session' and id > '$last_record_id' and (uid='$idno' or (uid = 0 AND (class = '$class' or class = ''))) order by id desc");
////////////

echo json_encode(array('status' => 1, 'data'=>"0", 'app_theme_color'=>$app_color, 'online_study_server'=>$study_server,
'is_cls_same'=>$is_cls_same,'modules'=>$data, 'student_status' => "$student_status","token_match"=>$token_match, "fee_display_type"=>$fee_display_type,
    "loc"=>$loc, "res_mode" => $res_mode, "student_house" => $medium, "house_color" => $mediumColor, 
    "enforce_session_change" => $enforce_session_change, "enforced_session" => $enforced_session, "student_message" => $student_message,
    "sibling_count" => $sibling_count, "new_notification" => $is_new_notification_available, "new_notification_count" => count($new_notification_count),

    "about_us" => get_about_us(), "contact_us" => get_contact(), "refund" => get_refund(), "privacy" => get_privacy(), "terms" => get_tnc(), "nav_item" => 0));


function checkSiblingCount($db, $idno){
    $stu_sib   = $db->getval("select sibling from student where idno = '$idno' ");
    $csvString = "$stu_sib";
    $options   = explode(",", $csvString);
    $options   = array_filter($options);

    return count($options);
}


function get_about_us(){
    return "Created in July 2001 “BRIGADIER TRIVEDI MEMORIAL EDUCATION SOCIETY HIGHER SECONDARY SCHOOL” is as now an established institution best known for stress of discipline, dedicated teaching, moral values and education related activities. It is being managed by the Brigadier Trivedi Memorial Education Society. In its first year we had classes from Nursery to III. As the year passed the school grew along with its children. We started our first batch of class VIII in 2006, X in 2008 and XII in 2011. 
            We want to make the child aware of himself, his abilities and his hidden talents in order to improve his personality and gain confidence in order to excel in life.";
}

function get_contact(){
    return "1.\t07554946033\n" . "2.\t07552742098\n" . "Email id : brigadier.tmschool@gmail.com\n";
}

function get_refund(){
    return "In most cases, No refund will be granted once the payment is done. However, exceptions may be made based on the following circumstances:
•	Multiple payments for same services.
•	A candidate paid the fee online but did not get the confirmation due to connection failure and the School is not able provide softcopy of the Fee Invoice.
Transaction fees charged would not be refunded/ reversed for any refund or reversal of any transaction.
________________________________________
NOTE
For online payments, it is important for candidates to note the transaction number and order no. for future reference and request for any type of Refund, for whatsoever reason, will be at the sole discretion of the School.
";
}

function get_privacy(){
    return "Brigadier trivedi memorial education society higher secondary school has adopted this privacy policy in order to ensure users of our commitment and dedication to privacy. Brigadier trivedi memorial education society higher secondary school respects your right to privacy. If we find it is absolutely necessary to contact you, we shall be contacting you.
Collection of IP addresses and the use of “Cookies”
When you visit our App, some information such as your Internet protocol address, Internet service provider, operating system, the App from which you arrived, and the time and date of your visit may be collected automatically as part of the software operation of this App. This intake of information is entirely anonymous. Brigadier trivedi memorial education society higher secondary school uses this information solely for internal marketing purposes, for example, to see what pages are most frequently visited in order to improve the App.
Personal Information
Brigadier trivedi memorial education society higher secondary school collects information that you have to submit for our record. We have to necessary share about you, your family members and ward this record with education department from time to time.
Brigadier trivedi memorial education society higher secondary school will not sell, distribute, or give your personal information to any third party without your knowledge and consent. Our school will not be liable for any personal information that you submit to external vendors or to any app / web site linked to this App.
Important security information - email scam
Brigadier trivedi memorial education society higher secondary school has been made aware of a number of fake emails that appear to be sent from Brigadier trivedi memorial education society higher secondary school asking users to confirm their email address and/or password. We would like to reassure users that we will never send you an email asking you to reconfirm your security details. We will never ask you to divulge any password or otp.
If you do receive a suspicious email or message like this, please delete it straight away and do not click on any of the links contained in it. If you are ever concerned about any communications that are or seem to be from our school, please contact us immediately.
";
}

function get_tnc(){
    return "This app, is owned and operated by the Brigadier Trivedi Memorial Education Society Higher Secondary School administration and staff. The app has been structured to provide information related to school and school activities and directly reflect all policies and procedures set forth by the Management. the Brigadier Trivedi Memorial Education Society Higher Secondary School has the right, at any time, to change or discontinue any feature or aspect of this app, for any reason; that is, without limitation, availability or equipment needed for accessing and utilizing this app.
Terms and Conditions of use
The utilization of this school app is governed by the policies, terms, and conditions set forth by the Brigadier Trivedi Memorial Education Society Higher Secondary School. Please read them thoroughly and carefully. Your use of this site indicates your acceptance of each of the terms and conditions of use, the Brigadier Trivedi Memorial Education Society Higher Secondary School reserves the right to modify this app in any fashion at any time as well as these Terms and Conditions of use.
Copyright and Trademark
•	This app contains copyrighted material, trademarks and other proprietary information including items such as photography, video, graphics, text, software and forms. Each of the items mentioned prior is subject to copyright laws. You may not modify, publish, display, transmit or subject yourself to the transfer or sale or in any form, exploit the content that exists on this app or that of any affiliates.
•	The data, information, materials, and services provided on this app are for use to benefit the students, parents, members, staff of the Brigadier Trivedi Memorial Education Society Higher Secondary School and beyond. Changes or modifications to pages, structures or procedures may incur at any time on this app. The materials on this app are provided in an “as is” state, without warranties of any type, either expressed or implied to the largest extent permissible to the applicable law.
•	You shall not upload, e-mail, post or make available in any other fashion any material on this app that is protected by copyright, trademark or other laws; that is, without direct permission from the absolute source.
Disclaimer of Warranty / Limitation of Website Liability
•	Agreement: You shall agree that the use of this app is at your sole risk. the Brigadier Trivedi Memorial Education Society Higher Secondary School, affiliates or any other organization or members, therein, shall not incur any responsibility for your use of this app. The school is not liable for any negative impact that is incurred to any one individual’s computer.
•	Limited License: Brigadier trivedi memorial education society higher secondary school app is for educational use. Unless otherwise expressed, you may not modify, copy, distribute, re-distribute, transmit, display, use, publish, license, create derivative material from, transfer, or sell any information or content contained anywhere on this app, via direct or indirect means.
•	Limitation of Liability: the Brigadier Trivedi Memorial Education Society Higher Secondary School shall not be liable for any loss or damage, including without limitation direct or indirect, special, economic, incidental or consequential damages, losses or expenses arising in connection with this site or use thereof or inability to use by any party, or in connection with any failure of performance, error, omission, interruption, defect, delay in operation or transmission, computer virus or line or system failure, even if School has been advised of the possibility of such damages, losses or expenses.
Post of Content
Brigadier trivedi memorial education society higher secondary school reserves the right, in its sole discretion, to refuse to post or remove any material submitted to, or posted on the app. Without limitation, the Brigadier Trivedi Memorial Education Society Higher Secondary School shall have the right to remove any material Brigadier trivedi memorial education society higher secondary school, in its sole discretion, which is finds to be in violation of the provisions hereof or otherwise objectionable, with regard to the standards of policies and procedures set forth the Brigadier Trivedi Memorial Education Society Higher Secondary School.
Modification of Terms
Brigadier trivedi memorial education society higher secondary school has the right to, at any time, change, or modify the terms and conditions applicable to the use of this app. Such changes or modifications shall be effective immediately upon notice thereof, which may be given by any means necessary in order to provide the most accurate and effective information possible.
We will be using the contact details of the prospective parent registering with us to reach them through any mode or medium.
Accounts and Security
If any of the service on the app requires you to open an account, you must complete the registration process by providing us with true, current, complete and accurate information as prompted by the applicable registration form, and you will maintain and promptly update such information to keep it true, current, complete and accurate. You also will choose a PASSWORD and a USER NAME. You are entirely responsible for maintaining the confidentially of your password and account. Furthermore, you are entirely responsible for any and all activities that occur under your account. You agree to notify Brigadier trivedi memorial education society higher secondary school of any unauthorized use of your account or any other breach of security. Brigadier trivedi memorial education society higher secondary school will not be liable for any loss that you may incur as a result of someone else using your password or account either with or without your knowledge. However, you could be held liable for losses incurred by Brigadier trivedi memorial education society higher secondary school or another party due to someone else using your account or password. You may not use anyone else’s account at any time, without the permission of the account holder. You acknowledge and agree that certain services may provide password-restricted access to customer information such as names and certain terms of your contracts. By using this app and registering for such services, you consent to Brigadier trivedi memorial education society higher secondary school display of such information via the services and accept all risks of unauthorized access to such information. If you provide any information that is false, inaccurate, out of date, or incomplete or Brigadier trivedi memorial education society higher secondary school has reasonable grounds to suspect that such information is false, inaccurate, not current, or incomplete, Brigadier trivedi memorial education society higher secondary school may suspend or terminate your account and refuse any and all current or future use of the services or any portion thereof. You are responsible for all costs and charges, including without limitation, phone charges and telecommunications equipment, that you incur in order to use the services.
No Unlawful or Prohibited Use
As a condition of your use of the app, you will not use the app for any purpose that is unlawful or prohibited by these terms, conditions, and notices. You may not use the services in any manner that could damage, disable, overburden, or impart any Brigadier trivedi memorial education society higher secondary school server, or the network(s) connected to any Brigadier trivedi memorial education society higher secondary school server, or interfere with any other party’s use and enjoyment of the website. You may not attempt to gain unauthorized access to services, materials, other accounts, computer systems or networks connected to any Brigadier trivedi memorial education society higher secondary school server or to the website, through hacking, password mining or any other means. You may not obtain or attempt to obtain any materials or information through any means not intentionally made available through the app.
Materials Provided to the Brigadier Trivedi Memorial Education Society Higher Secondary School
Unless otherwise specified, Brigadier trivedi memorial education society higher secondary school does not claim ownership of the materials you provide to Brigadier trivedi memorial education society higher secondary school (including, without limitation, information, ideas, concepts, techniques, feedback, data, questions, comments and suggestions, or the like) or post, upload, input or submit to the app or its associated services for review by Brigadier trivedi memorial education society higher secondary school, the general public, and/ or by the members of any public or private community (each a “Submission” and collectively “submission”) and such submissions shall be deemed not to be confidential. However, by posting, uploading, inputting, providing or submitting (“posting”) your submission you are granting Brigadier trivedi memorial education society higher secondary school, its affiliated companies and necessary sublicensees permission to use your submission in connection with the operation of their businesses (including, without limitation, all Brigadier trivedi memorial education society higher secondary school), including without limitation, the license rights to copy, distribute, transmit, publicly display, publicly perform, reproduce, edit, modify, translate and reformat your submissions; to publish your name in connection with your submission; develop, manufacture, and market products incorporating such ideas, concepts, or techniques, and the right to sublicense such rights to any supplier of the services and/or materials on the app.

No compensation will be paid with respect to the use of your submission, as provided herein. Brigadier trivedi memorial education society higher secondary school is under no obligation to post or use any Submission you may provide and Podar Education Network may remove any Submission at any time in its sole discretion. By posting a submission you warrant and represent that you own or otherwise control all of the rights to your Submission as described in these Terms of Use including, without limitation, all the rights necessary for you to provide, post, upload, input or submit the submission.

You acknowledge that Brigadier trivedi memorial education society higher secondary school does not pre-screen Submissions, but that Brigadier trivedi memorial education society higher secondary school and its designees have the right (but not the obligation) in their sole discretion to block or restrict access to or the availability of or to disable, any Submissions that is available via the app. Without limiting the foregoing, Brigadier trivedi memorial education society higher secondary school and its designees may disable, restrict access to or the availability of, any Submissions that violates the Terms of Use or is otherwise objectionable. You must evaluate, and bear all risks associated with, the use of any Submissions, including any reliance on the accuracy, completeness, or usefulness of such Submissions.

You understand all Submissions, whether publicly posted or privately transmitted, are the sole responsibility of the person from whom such Submissions originated. This means that you, and not Brigadier trivedi memorial education society higher secondary school, are entirely responsible for all Submissions that you upload, post, provide, input, submit or otherwise transmit via the website. Brigadier trivedi memorial education society higher secondary school does not control the Submissions posted via the app and, as such, does not guarantee the accuracy, integrity or quality of such Submissions. You understand that by using the website, you may be exposed to Submissions from others that are offensive, indecent or objectionable.
Spam E-mail and Postings
You agree that Brigadier trivedi memorial education society higher secondary school would be irreparably harmed by the use, by you or others, of the website or facilities in connection with the transmission of spam newsgroup postings or unsolicited e-mail in violation of these Terms of Use, and that Brigadier trivedi memorial education society higher secondary school is entitled to obtain injunctive relief against any such transmission (in addition to all other remedies available at law or in equity). Brigadier trivedi memorial education society higher secondary school reserves the right to block, filter or delete unsolicited e-mail.
Indemnity
You agree to indemnify, defend and hold Brigadier trivedi memorial education society higher secondary school, and its subsidiaries, affiliates, officers, agents, co-branders, partners, and employees, harmless from any claim or demand, including reasonable attorneys fees, made by any third party due to or arising out of your Submissions, your use of the website including any use by your employees, your connection to the website, your violation of the Terms of Use, or your violation any rights of another.
Summary of Agreement
Each of the prior Terms and Conditions of Use validates the entire agreement between Podar Education Network and you, as the user or visitor of the Brigadier trivedi memorial education society higher secondary school app. Any changes to these Terms and Conditions of Use take effect immediately.
";
}