<?php
include("../public/impOpreation.php");
$do = $_GET['do'];
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d");

if (empty($do)) {  
    $smarty->assign("date", $date);
    $tables = ['students','studentsubjects','studentaddsubjects','studentabsences','studentsexams','studentspaymentsystems','studentspays'];
    foreach ($tables as $table) {
        
       $tableadd = R::count($table,'del < 2');
       $tabledel = R::count($table,'del > 1');
       $smarty->assign($table."add",$tableadd);  
       $smarty->assign($table."del",$tabledel);    
    }
    $smarty->display("header.html");
    $smarty->display("studentsreportsview/show.html");
    $smarty->assign("student", 1);
    $smarty->display("footer.html");
} elseif ($do == "students") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentid = filter_input(INPUT_POST, 'studentid');
    $searchQuery = ' where 1 ';
    if ($studentid) {
        $searchQuery .=' and studentid  = "' . $studentid . '" ';
    }
    
     if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
     }
     
     if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
     }
   

    $students = R::load('students',$studentid);
    if ($students->del < 2) {
        $user = R::findOne('user','userid = ?',[$students->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$students->deluserid]);
        $students->addtoday = $students->deltoday;

    }
     $branch = R::getRow("SELECT branch.* FROM `branch` WHERE branchId = $students->branchid ");
    $students->branch = $branch['branchName'];
    $students->employeename = $user->employeename;
    $smarty->assign("students", $students);

    $studentaddsubjectdetails = R::findAll('studentaddsubjectdetails',"$searchQuery");
    foreach($studentaddsubjectdetails as $data){
        if ($data->del < 2) {
        $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentaddsubjectdetaildel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;

        }
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->subjectname = $studentsubjects->subjectname;
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->subjectgroupprice = $studentsubjectgroups->subjectgroupprice;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentaddsubjectdetaildel", $studentaddsubjectdetaildel); 
    $smarty->assign("studentaddsubjectdetails", $studentaddsubjectdetails); 


   $studentsexamsval = R::findAll('studentsexamsval',"$searchQuery");
    foreach($studentsexamsval as $data){
        if ($data->del < 2) {
        $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentsexamsvaldel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;

        }
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $data->subjectname = $studentsubjects->subjectname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentsexamsvaldel", $studentsexamsvaldel); 
    $smarty->assign("studentsexamsvals", $studentsexamsval); 


    $studentspays = R::findAll('studentspays',"$searchQuery");
    foreach($studentspays as $data){
        if ($data->del < 2) {
            $payprice += $data->payprice;
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentspaydel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;

        }
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $data->subjectname = $studentsubjects->subjectname;    
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentspaydel", $studentspaydel);
    $smarty->assign("studentspays", $studentspays);

    $studentabsences = R::findAll('studentabsences',"$searchQuery  and onlys = 1");
    foreach($studentabsences as $data){
        if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentabsencesdel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;

        }
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $data->subjectname = $studentsubjects->subjectname; 
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentabsencesdel", $studentabsencesdel);  
    $smarty->assign("studentabsences", $studentabsences);  
    $smarty->assign("payprice", $payprice);



    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/students.html");
} elseif ($do == "studentsubjects") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentsubjectid = filter_input(INPUT_POST, 'studentsubjectid');
    $searchQuery =' where 1 ';
    if ($studentsubjectid) {
        $searchQuery .=' and studentsubjectid  = "' . $studentsubjectid . '" ';
    }
    
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
     }
     
     if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
     }
   

    $studentsubjects = R::load('studentsubjects',$studentsubjectid);
    if ($studentsubjects->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentsubjects->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentsubjects->deluserid]);
        $studentsubjects->addtoday = $studentsubjects->deltoday;
    }
    $studentsubjects->employeename = $user->employeename;
    $smarty->assign("studentsubjects", $studentsubjects);


    $studentsubjectgroups = R::findAll('studentsubjectgroups',"$searchQuery");
    foreach($studentsubjectgroups as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentsubjectgroupdel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $data->daytimes = R::findAll('studentsubjectgroupdays','studentsubjectgroupid = ?',[$data->id]);
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentsubjectgroupdel", $studentsubjectgroupdel); 
    $smarty->assign("studentsubjectgroups", $studentsubjectgroups); 


    $studentaddsubjectdetails = R::findAll('studentaddsubjectdetails',"$searchQuery");
    foreach($studentaddsubjectdetails as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentaddsubjectdetaildel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->studentname = $students->studentname;
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->subjectgroupprice = $studentsubjectgroups->subjectgroupprice;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentaddsubjectdetaildel", $studentaddsubjectdetaildel); 
    $smarty->assign("studentaddsubjectdetails", $studentaddsubjectdetails); 


    $studentsexams = R::findAll('studentsexams',"$searchQuery");
    foreach($studentsexams as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentsexamdel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
         $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentsexamdel", $studentsexamdel); 
    $smarty->assign("studentsexams", $studentsexams); 


    $studentspays = R::findAll('studentspays',"$searchQuery");
    foreach($studentspays as $data){
        if ($data->del < 2) {
            $payprice += $data->payprice;
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentspaydel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $data->employeename = $user->employeename;
        
    }
    $smarty->assign("studentspaydel", $studentspaydel);
    $smarty->assign("studentspays", $studentspays);

    $studentabsences = R::findAll('studentabsences',"$searchQuery and onlys = 1");
    foreach($studentabsences as $data){
        if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentabsencesdel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentabsencesdel", $studentabsencesdel);  
    $smarty->assign("studentabsences", $studentabsences);  
    $smarty->assign("payprice", $payprice);

    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/studentsubjects.html");
} elseif ($do == "studentaddsubjects") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentaddsubjectid = filter_input(INPUT_POST, 'studentaddsubjectid');
    $searchQuery =' where 1 ';
    if ($studentaddsubjectid) {
        $searchQuery .=' and studentaddsubjectid  = "' . $studentaddsubjectid . '" ';
    }
     if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
     }
     
     if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
     }
   
    $studentaddsubjects = R::load('studentaddsubjects',$studentaddsubjectid);
    if ($studentaddsubjects->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentaddsubjects->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentaddsubjects->deluserid]);
         $studentaddsubjects->addtoday = $studentaddsubjects->deltoday;
    }
    $studentsubjects = R::load('studentsubjects',$studentaddsubjects->studentsubjectid);
    $studentsubjectgroups = R::load('studentsubjectgroups',$studentaddsubjects->studentsubjectgroupid);
    $studentaddsubjects->subjectname = $studentsubjects->subjectname;
    $studentaddsubjects->deviceid = $studentsubjects->deviceid;
    $studentaddsubjects->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentaddsubjects->subjectgroupprice = $studentsubjectgroups->subjectgroupprice;
    $studentaddsubjects->employeename = $user->employeename;
    $smarty->assign("studentaddsubjects", $studentaddsubjects);


    $studentaddsubjectdetails = R::findAll('studentaddsubjectdetails',"$searchQuery");
    foreach($studentaddsubjectdetails as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentaddsubjectdetaildel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
             $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentaddsubjectdetaildel", $studentaddsubjectdetaildel); 
    $smarty->assign("studentaddsubjectdetails", $studentaddsubjectdetails); 


    $studentsexams = R::findAll('studentsexams',"$searchQuery");
    foreach($studentsexams as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentsexamdel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
             $data->addtoday = $data->deltoday;
        }
      
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentsexamdel", $studentsexamdel); 
    $smarty->assign("studentsexams", $studentsexams); 


    $studentspays = R::findAll('studentspays',"$searchQuery");
    foreach($studentspays as $data){
        if ($data->del < 2) {
            $payprice += $data->payprice;
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentspaydel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
             $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentspaydel", $studentspaydel);
    $smarty->assign("studentspays", $studentspays);

    $studentabsences = R::findAll('studentabsences',"$searchQuery and onlys = 1");
    foreach($studentabsences as $data){
        if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentabsencesdel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
             $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentabsencesdel", $studentabsencesdel);  
    $smarty->assign("studentabsences", $studentabsences);  
    $smarty->assign("payprice", $payprice);


    


    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/studentaddsubjects.html");
} else if ($do == "studentabsences") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentabsenceid = filter_input(INPUT_POST, 'studentabsenceid');
    
    $searchQuery =' where 1 ';
   if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }else{
         $searchQuery .=' and addtoday  >= "' . $date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }else{
        $searchQuery .=' and addtoday <= "' . $date . ' 23-59-55" ';
    }
    $studentabsence = R::load('studentabsences',$studentabsenceid);
    if ($studentabsence->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentabsence->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentabsence->deluserid]);
        $studentabsence->addtoday = $studentabsence->deltoday;
    }
     $students = R::load('students',$studentabsence->studentid);
        $studentabsence->studentname = $students->studentname;
        $studentsubjects = R::load('studentsubjects',$studentabsence->studentsubjectid);
        $studentsubjectgroups = R::load('studentsubjectgroups',$studentabsence->studentsubjectgroupid);
        $studentabsence->subjectname = $studentsubjects->subjectname;
        $studentabsence->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentabsence->employeename = $user->employeename;
    $smarty->assign("studentabsence", $studentabsence);
    
    $studentabsences = R::findAll('studentabsences',"$searchQuery and  onlys = 1 ");
    foreach($studentabsences as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentabsencedel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
             $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->subjectname = $studentsubjects->subjectname;
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentabsencedel", $studentabsencedel); 
    $smarty->assign("studentabsences", $studentabsences); 


    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/studentabsences.html");
} elseif ($do == "studentsexams") {
    include_once("../public/authentication.php");
     $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentsexamid = filter_input(INPUT_POST, 'studentsexamid');
   
    $searchQuery =' where 1 ';
     if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
     }
     
     if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
     }
     
    if ($studentsexamid) {
        $searchQuery .=' and studentsexamid  = "' . $studentsexamid . '" ';
    }
    $studentsexams = R::load('studentsexams',$studentsexamid);
    if ($studentsexams->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentsexams->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentsexams->deluserid]);
        $studentsexams->addtoday = $studentsexams->deltoday;
    }
    $studentsubjects = R::load('studentsubjects',$studentsexams->studentsubjectid);
    $studentsubjectgroups = R::load('studentsubjectgroups',$studentsexams->studentsubjectgroupid);
    $studentsexams->subjectname = $studentsubjects->subjectname;
    $studentsexams->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentsexams->employeename = $user->employeename;
    $smarty->assign("studentsexams", $studentsexams);


    $studentsexamsvals = R::findAll('studentsexamsval',"$searchQuery");
    foreach($studentsexamsvals as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentsexamsvaldel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
             $data->addtoday = $data->deltoday;
        }
        $data->employeename = $user->employeename;
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
    }
    
    $smarty->assign("studentsexamsvaldel", $studentsexamsvaldel); 
    $smarty->assign("studentsexamsvals", $studentsexamsvals); 


    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/studentsexams.html");
} elseif ($do == "studentspaymentsystems") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentspaymentsystemid = filter_input(INPUT_POST, 'studentspaymentsystemid');
    $searchQuery =' where 1 ';
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }else{
         $searchQuery .=' and addtoday  >= "' . $date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }else{
        $searchQuery .=' and addtoday <= "' . $date . ' 23-59-55" ';
    }
    if ($studentspaymentsystemid) {
        $searchQuery .=' and studentspaymentsystemid  = "' . $studentspaymentsystemid . '" ';
    }
    $studentspaymentsystems = R::load('studentspaymentsystems',$studentspaymentsystemid);
    if ($studentspaymentsystems->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentspaymentsystems->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentspaymentsystems->deluserid]);
        $studentspaymentsystems->addtoday = $studentspaymentsystems->deltoday;
    }
     $studentsubjects = R::load('studentsubjects',$studentspaymentsystems->studentsubjectid);
    $studentspaymentsystems->subjectname = $studentsubjects->subjectname;
    $studentspaymentsystems->employeename = $user->employeename;
    $smarty->assign("studentspaymentsystems", $studentspaymentsystems);


    $studentspays = R::findAll('studentspays',"$searchQuery");
    foreach($studentspays as $data){
        if ($data->del < 2) {
            $payprice += $data->payprice;
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentspaydel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->subjectname = $studentsubjects->subjectname;
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentspaydel", $studentspaydel); 
    $smarty->assign("studentspays", $studentspays); 
    $smarty->assign("payprice", $payprice); 


    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/studentspaymentsystems.html");
} elseif ($do == "studentspays") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentspayid = filter_input(INPUT_POST, 'studentspayid');
    $searchQuery =' where 1 ';
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }else{
         $searchQuery .=' and addtoday  >= "' . $date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }else{
        $searchQuery .=' and addtoday <= "' . $date . ' 23-59-55" ';
    }
    
    $studentspay = R::load('studentspays',$studentspayid);
    if ($studentspay->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentspay->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentspay->deluserid]);
        $studentspay->addtoday = $studentspay->deltoday;
    }
    $students = R::load('students',$studentspay->studentid);
    $studentspay->studentname = $students->studentname;
    $studentsubjects = R::load('studentsubjects',$studentspay->studentsubjectid);
    $studentsubjectgroups = R::load('studentsubjectgroups',$studentspay->studentsubjectgroupid);
    $studentspay->subjectname = $studentsubjects->subjectname;
    $studentspay->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentspay->employeename = $user->employeename;
    $smarty->assign("studentspay", $studentspay);
    $studentspays = R::findAll('studentspays',"$searchQuery");
    foreach($studentspays as $data){
        if ($data->del < 2) {
            $payprice += $data->payprice;
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentspaydel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $data->subjectname = $studentsubjects->subjectname;
        $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentspaydel", $studentspaydel); 
    $smarty->assign("studentspays", $studentspays); 
    $smarty->assign("payprice", $payprice); 


    $smarty->assign("student", 1);
    $smarty->display("studentsreportsview/studentspays.html");
}else if ($do == "studentsget" ) {
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentid = filter_input(INPUT_POST, 'studentid');
    $studentaddsubjectdetailid = filter_input(INPUT_POST, 'studentaddsubjectdetailid');
    $studentsexamsvalid = filter_input(INPUT_POST, 'studentsexamsvalid');
    $studentspayid = filter_input(INPUT_POST, 'studentspayid');
    $studentabsenceid = filter_input(INPUT_POST, 'studentabsenceid');
    $onlys = filter_input(INPUT_POST, 'onlys');
     $searchQuery =' where 1 ';
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }
    
    if ($studentid) {
        $searchQuery .=' and studentid  = "' . $studentid . '" ';
    }
    $students = R::load('students',$studentid);
    if ($students->del < 2) {
        $user = R::findOne('user','userid = ?',[$students->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$students->deluserid]);
        $students->addtoday = $students->deltoday;
    }
    $branch = R::getRow("SELECT branch.* FROM `branch` WHERE branchId = $students->branchid ");
    $students->branch = $branch['branchName'];
    $students->employeename = $user->employeename;
    $smarty->assign("students", $students);
    
    

    if ($studentaddsubjectdetailid) {
        $studentaddsubjectdetails = R::load('studentaddsubjectdetails',$studentaddsubjectdetailid);
        $searchQuery2 =' and studentaddsubjectid  = "' . $studentaddsubjectdetails->studentaddsubjectid . '" ';
        if ($studentaddsubjectdetails->del < 2) {
            $user = R::findOne('user','userid = ?',[$studentaddsubjectdetails->adduserid]);
        }else{
            $user = R::findOne('user','userid = ?',[$studentaddsubjectdetails->deluserid]);
            $studentaddsubjectdetails->addtoday = $studentaddsubjectdetails->deltoday;
        }
        $studentsubjects = R::load('studentsubjects',$studentaddsubjectdetails->studentsubjectid);
        $studentaddsubjectdetails->subjectname = $studentsubjects->subjectname;
        $studentsubjectgroups = R::load('studentsubjectgroups',$studentaddsubjectdetails->studentsubjectgroupid);
        $studentaddsubjectdetails->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $studentaddsubjectdetails->subjectgroupprice = $studentsubjectgroups->subjectgroupprice;
        $studentaddsubjectdetails->employeename = $user->employeename;
        $smarty->assign("studentaddsubjectdetailid", $studentaddsubjectdetailid); 
    }else{
        $studentaddsubjectdetails = R::findAll('studentaddsubjectdetails',"$searchQuery");
        foreach($studentaddsubjectdetails as $data){
            if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentaddsubjectdetaildel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
            $data->subjectname = $studentsubjects->subjectname;
            $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
            $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
            $data->subjectgroupprice = $studentsubjectgroups->subjectgroupprice;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentaddsubjectdetaildel", $studentaddsubjectdetaildel); 
    }
    $smarty->assign("studentaddsubjectdetails", $studentaddsubjectdetails); 

   
   
    if ($studentsexamsvalid) {
        $studentsexamsval = R::load('studentsexamsval',$studentsexamsvalid);
        if ($studentsexamsval->del < 2) {
            $user = R::findOne('user','userid = ?',[$studentsexamsval->adduserid]);
        }else{
            $studentsexamsvaldel += 1;
            $user = R::findOne('user','userid = ?',[$studentsexamsval->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $studentsubjects = R::load('studentsubjects',$studentsexamsval->studentsubjectid);
        $studentsexamsval->subjectname = $studentsubjects->subjectname;
        $studentsexamsval->employeename = $user->employeename;
        $smarty->assign("studentsexamsvalid", $studentsexamsvalid); 
    }else{
         $studentsexamsval = R::findAll('studentsexamsval',"$searchQuery $searchQuery2");
        foreach($studentsexamsval as $data){
            if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentsexamsvaldel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
               
            }
            $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
            $data->subjectname = $studentsubjects->subjectname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentsexamsvaldel", $studentsexamsvaldel); 
    }
    $smarty->assign("studentsexamsvals", $studentsexamsval); 

    if ($studentspayid) {
        $studentspays = R::load('studentspays',$studentspayid);
        if ($studentspays->del < 2) {
            $payprice += $studentspays->payprice;
            $user = R::findOne('user','userid = ?',[$studentspays->adduserid]);
        }else{
            $user = R::findOne('user','userid = ?',[$studentspays->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $studentsubjects = R::load('studentsubjects',$studentspays->studentsubjectid);
        $studentspays->subjectname = $studentsubjects->subjectname;
        $studentspays->employeename = $user->employeename;
        $smarty->assign("studentspayid", $studentspayid);
    }else{
        $studentspays = R::findAll('studentspays',"$searchQuery $searchQuery2");
        foreach($studentspays as $data){
            if ($data->del < 2) {
                $payprice += $data->payprice;
                $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentspaydel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
            $data->subjectname = $studentsubjects->subjectname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentspaydel", $studentspaydel);

    }
    $smarty->assign("studentspays", $studentspays);

     if ($studentabsenceid) {
        $studentabsences = R::load('studentabsences',$studentabsenceid);
            if ($studentabsences->del < 2) {
                $user = R::findOne('user','userid = ?',[$studentabsences->adduserid]);
            }else{
                $user = R::findOne('user','userid = ?',[$studentabsences->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $studentsubjects = R::load('studentsubjects',$studentabsences->studentsubjectid);
            $studentabsences->subjectname = $studentsubjects->subjectname;
            $studentabsences->employeename = $user->employeename;
        
        $smarty->assign("studentabsenceid", $studentabsenceid); 
     }else{
        $studentabsences = R::findAll('studentabsences',"$searchQuery $searchQuery2 and onlys = $onlys");
        foreach($studentabsences as $data){
            if ($data->del < 2) {
                $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentabsencesdel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
            $data->subjectname = $studentsubjects->subjectname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentabsencesdel", $studentabsencesdel); 
    }
     
    $smarty->assign("studentabsences", $studentabsences);  
    $smarty->assign("payprice", $payprice);



    $smarty->assign("student", 1);
    $smarty->display("studentsreportdetailsview/students.html");
}else if ($do == "studentaddsubjectsget" ) {
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentaddsubjectid = filter_input(INPUT_POST, 'studentaddsubjectid');
    $studentaddsubjectdetailid = filter_input(INPUT_POST, 'studentaddsubjectdetailid');
    $studentsexamid = filter_input(INPUT_POST, 'studentsexamid');
    $studentspaymentsystemid = filter_input(INPUT_POST, 'studentspaymentsystemid');
    $studentabsenceid = filter_input(INPUT_POST, 'studentabsenceid');
    $studentspayid = filter_input(INPUT_POST, 'studentspayid');
    $onlys = filter_input(INPUT_POST, 'onlys');
     $searchQuery =' where 1 ';
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }

    if ($studentaddsubjectid) {
        $searchQuery .=' and studentaddsubjectid  = "' . $studentaddsubjectid . '" ';
    }
    $studentaddsubjects = R::load('studentaddsubjects',$studentaddsubjectid);
    if ($studentaddsubjects->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentaddsubjects->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentaddsubjects->deluserid]);
    }
    $studentsubjects = R::load('studentsubjects',$studentaddsubjects->studentsubjectid);
    $studentaddsubjects->subjectname = $studentsubjects->subjectname;
    $studentsubjectgroups = R::load('studentsubjectgroups',$studentaddsubjects->studentsubjectgroupid);
    $studentaddsubjects->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentaddsubjects->subjectgroupprice = $studentsubjectgroups->subjectgroupprice;
    $studentaddsubjects->employeename = $user->employeename;
    $smarty->assign("studentaddsubjects", $studentaddsubjects);

   if ($studentaddsubjectdetailid) {
        $studentaddsubjectdetails = R::load('studentaddsubjectdetails',$studentaddsubjectdetailid);
        $searchQuery2 =' and studentaddsubjectid  = "' . $studentaddsubjectdetails->studentaddsubjectid . '" ';
        if ($studentaddsubjectdetails->del < 2) {
            $user = R::findOne('user','userid = ?',[$studentaddsubjectdetails->adduserid]);
        }else{
            $user = R::findOne('user','userid = ?',[$studentaddsubjectdetails->deluserid]);
            $studentaddsubjectdetails->addtoday = $studentaddsubjectdetails->deltoday;
        }
        $students = R::load('students',$studentaddsubjectdetails->studentid);
        $studentaddsubjectdetails->studentname = $students->studentname;
        $studentaddsubjectdetails->employeename = $user->employeename;
        $smarty->assign("studentaddsubjectdetailid", $studentaddsubjectdetailid); 
    }else{
        $studentaddsubjectdetails = R::findAll('studentaddsubjectdetails',"$searchQuery");
        foreach($studentaddsubjectdetails as $data){
            if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentaddsubjectdetaildel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $students = R::load('students',$data->studentid);
            $data->studentname = $students->studentname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentaddsubjectdetaildel", $studentaddsubjectdetaildel); 
    }
    $smarty->assign("studentaddsubjectdetails", $studentaddsubjectdetails); 
    
    if ($studentsexamid) {
        $studentsexams = R::load('studentsexams',$studentsexamid);
        if ($studentsexams->del < 2) {
            $user = R::findOne('user','userid = ?',[$studentsexams->adduserid]);
        }else{
            $user = R::findOne('user','userid = ?',[$studentsexams->deluserid]);
        }
        $studentsexams->employeename = $user->employeename;
        $smarty->assign("studentsexamid", $studentsexamid); 
    }else{
         $studentsexams = R::findAll('studentsexams',"$searchQuery $searchQuery2");
        foreach($studentsexams as $data){
            if ($data->del < 2) {
            $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentsexamdel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
            }
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentsexamdel", $studentsexamdel); 
    }
    $smarty->assign("studentsexams", $studentsexams); 


      if ($studentspayid) {
        $studentspays = R::load('studentspays',$studentspayid);
        if ($studentspays->del < 2) {
            $payprice += $studentspays->payprice;
            $user = R::findOne('user','userid = ?',[$studentspays->adduserid]);
        }else{
            $user = R::findOne('user','userid = ?',[$studentspays->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $studentsubjects = R::load('studentsubjects',$studentspays->studentsubjectid);
        $studentspays->subjectname = $studentsubjects->subjectname;
        $studentspays->employeename = $user->employeename;
        $smarty->assign("studentspayid", $studentspayid);
    }else{
        $studentspays = R::findAll('studentspays',"$searchQuery $searchQuery2");
        foreach($studentspays as $data){
            if ($data->del < 2) {
                $payprice += $data->payprice;
                $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentspaydel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
            $data->subjectname = $studentsubjects->subjectname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentspaydel", $studentspaydel);

    }
    $smarty->assign("studentspays", $studentspays);

     if ($studentabsenceid) {
        $studentabsences = R::load('studentabsences',$studentabsenceid);
            if ($studentabsences->del < 2) {
                $user = R::findOne('user','userid = ?',[$studentabsences->adduserid]);
            }else{
                $user = R::findOne('user','userid = ?',[$studentabsences->deluserid]);
                $data->addtoday = $data->deltoday;
            }
           $students = R::load('students',$studentabsences->studentid);
            $studentabsences->studentname = $students->studentname;
            $studentabsences->employeename = $user->employeename;
        
        $smarty->assign("studentabsenceid", $studentabsenceid); 
     }else{
        $studentabsences = R::findAll('studentabsences',"$searchQuery $searchQuery2 and onlys = $onlys");
        foreach($studentabsences as $data){
            if ($data->del < 2) {
                $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentabsencesdel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $students = R::load('students',$data->studentid);
            $data->studentname = $students->studentname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentabsencesdel", $studentabsencesdel); 
    }
     
    $smarty->assign("studentabsences", $studentabsences);  
    $smarty->assign("payprice", $payprice);



    $smarty->assign("student", 1);
    $smarty->display("studentsreportdetailsview/studentaddsubjects.html");
}else if ($do == "studentsexamsget" ) {
  include_once("../public/authentication.php");
     $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentsexamid = filter_input(INPUT_POST, 'studentsexamid');
    $searchQuery =' where 1 ';
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }

    if ($studentsexamid) {
        $searchQuery .=' and studentsexamid  = "' . $studentsexamid . '" ';
    }
    $studentsexams = R::load('studentsexams',$studentsexamid);
    if ($studentsexams->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentsexams->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentsexams->deluserid]);
        $studentsexams->addtoday = $studentsexams->deltoday;
    }
    $studentsubjects = R::load('studentsubjects',$studentsexams->studentsubjectid);
    $studentsexams->subjectname = $studentsubjects->subjectname;
    $studentsubjectgroups = R::load('studentsubjectgroups',$studentsexams->studentsubjectgroupid);
    $studentsexams->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentsexams->employeename = $user->employeename;
    $smarty->assign("studentsexams", $studentsexams);


    $studentsexamsvals = R::findAll('studentsexamsval',"$searchQuery");
    foreach($studentsexamsvals as $data){
        if ($data->del < 2) {
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentsexamsvaldel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentsexamsvaldel", $studentsexamsvaldel); 
    $smarty->assign("studentsexamsvals", $studentsexamsvals); 


    $smarty->assign("student", 1);
    $smarty->display("studentsreportdetailsview/studentsexams.html");
} else if ($do == "studentspaysget") {
     include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentspayid = filter_input(INPUT_POST, 'studentspayid');
    $searchQuery =' where 1 ';
    if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
    }
     
    if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
    }
    
    $studentspay = R::load('studentspays',$studentspayid);
    if ($studentspay->del < 2) {
        $user = R::findOne('user','userid = ?',[$studentspay->adduserid]);
    }else{
        $user = R::findOne('user','userid = ?',[$studentspay->deluserid]);
        $studentspay->addtoday = $studentspay->deltoday;
    }
    $students = R::load('students',$studentspay->studentid);
    $studentspay->studentname = $students->studentname;
    $studentsubjects = R::load('studentsubjects',$studentspay->studentsubjectid);
    $studentspay->subjectname = $studentsubjects->subjectname;
    $studentsubjectgroups = R::load('studentsubjectgroups',$studentspay->studentsubjectgroupid);
    $studentspay->subjectgroupname = $studentsubjectgroups->subjectgroupname;
    $studentspay->employeename = $user->employeename;
    $smarty->assign("studentspay", $studentspay);
    $studentspays = R::findAll('studentspays',"$searchQuery");
    foreach($studentspays as $data){
        if ($data->del < 2) {
            $payprice += $data->payprice;
           $user = R::findOne('user','userid = ?',[$data->adduserid]);
        }else{
            $studentspaydel += 1;
            $user = R::findOne('user','userid = ?',[$data->deluserid]);
            $data->addtoday = $data->deltoday;
        }
        $students = R::load('students',$data->studentid);
        $data->studentname = $students->studentname;
        $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
        $data->subjectname = $studentsubjects->subjectname;
        $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
        $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
        $data->employeename = $user->employeename;
    }
    $smarty->assign("studentspaydel", $studentspaydel); 
    $smarty->assign("studentspays", $studentspays); 
    $smarty->assign("payprice", $payprice); 


    $smarty->assign("student", 1);
    $smarty->display("studentsreportdetailsview/studentspays.html");
} elseif ($do == "studentabsencesget") {
    include_once("../public/authentication.php");
    $start_date = filter_input(INPUT_POST, 'start_date');
    $end_date = filter_input(INPUT_POST, 'end_date');
    $studentaddsubjectid = filter_input(INPUT_POST, 'studentaddsubjectid');
    $studentaddsubjectdetailid = filter_input(INPUT_POST, 'studentaddsubjectdetailid');
    $onlys = filter_input(INPUT_POST, 'onlys');
    $searchQuery = ' where 1 ';
    if ($studentaddsubjectid) {
        $searchQuery .=' and studentaddsubjectid = "' . $studentaddsubjectid . '" ';
    }
    
    if ($studentaddsubjectdetailid) {
        $searchQuery .=' and studentaddsubjectdetailid  = "' . $studentaddsubjectdetailid . '" ';
    }
    
    if ($onlys) {
        $searchQuery .=' and onlys  = "' . $onlys . '" ';
    }else{
        $searchQuery .=' and onlys  = 0 '; 
    }
    
     if ($start_date) {
         $searchQuery .=' and addtoday  >= "' . $start_date . ' 00-00-00"  ';
     }
     
     if ($end_date) {
         $searchQuery .=' and addtoday <= "' . $end_date . ' 23-59-55" ';
     }
   
 
        $studentabsences = R::findAll('studentabsences'," $searchQuery ");
        foreach($studentabsences as $data){
            if ($data->del < 2) {
                $user = R::findOne('user','userid = ?',[$data->adduserid]);
            }else{
                $studentabsencesdel += 1;
                $user = R::findOne('user','userid = ?',[$data->deluserid]);
                $data->addtoday = $data->deltoday;
            }
            $students = R::load('students',$data->studentid);
            $branch = R::getRow("SELECT branch.* FROM `branch` WHERE branchId = ? ",[$students->branchid]);
            $data->branchname = $branch['branchName'];
            $data->datebirth = $students->datebirth;
            $data->studentname = $students->studentname;
            $data->employeename = $user->employeename;
            $studentsubjects = R::load('studentsubjects',$data->studentsubjectid);
            $data->subjectname = $studentsubjects->subjectname;
            $studentsubjectgroups = R::load('studentsubjectgroups',$data->studentsubjectgroupid);
            $data->subjectgroupname = $studentsubjectgroups->subjectgroupname;
            $data->employeename = $user->employeename;
        }
        $smarty->assign("studentabsencesdel", $studentabsencesdel); 
         $smarty->assign("studentabsences", $studentabsences); 
    

    $smarty->assign("student", 1);
    $smarty->display("studentsreportdetailsview/studentabsences.html");
}
?>