<?php

//fetch branch code
function getInstitutionCode($conn_rjllearning, $institution_id)
{
    $sql = "Select institution_code from institutions where id = ?";
    $validate_user = $conn_rjllearning->prepare($sql);
    $validate_user->execute(array($institution_id));
    $result_code = $validate_user->fetchAll();

    if (count($result_code) == 1) {
        $institution_code = $result_code[0]['institution_code'];

        return $institution_code;
    } else {
        return false;
    }
}


//fetch branch code
function getBranchCode($conn_rjllearning, $branch_id, $institution_id)
{
    $sql = "Select branch_code from branch where id = ? and institution_id = ?";
    $validate_user = $conn_rjllearning->prepare($sql);
    $validate_user->execute(array($branch_id, $institution_id));
    $result_code = $validate_user->fetchAll();
    if (count($result_code) == 1) {
        $branch_code = $result_code[0]['branch_code'];
        return $branch_code;
    } else {
        return false;
    }
}

function insertStudentRegistration($conn_rjllearning_specific, $institution_id, $branch_id, $reg_no, $name, $fathername, $mothername, $mobile, $email, $address_line_1, $city, $pincode, $dob, $gender, $reg_fees, $paid_through, $refrence_number, $for_class, $last_school, $current_class, $username,$sibling_bool,$sibling)
{
    $sql = "INSERT INTO  student_registration(institution_id,branch_id,reg_no,name,fathername,mothername,mobile,email,address_line_1,city,pincode,dob,gender,reg_fees,paid_through,refrence_number,for_class,last_school,current_class,sibling_bool,sibling,date_added,added_by,status)
                             VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    $stmt =  $conn_rjllearning_specific->prepare($sql);
    $stmt->execute(array($institution_id, $branch_id, $reg_no, $name, $fathername, $mothername, $mobile, $email, $address_line_1, $city, $pincode, $dob, $gender, $reg_fees, $paid_through, $refrence_number, $for_class, $last_school, $current_class,$sibling_bool,$sibling, date('Y-m-d'), $username, '1'));
    $registration_id = $conn_rjllearning_specific->lastInsertId();

    return $registration_id;
}

function updateStudentRegistration($conn_rjllearning_specific, $reg_id, $institution_id, $branch_id, $reg_no, $name, $fathername, $mothername, $mobile, $email, $address_line_1, $city, $pincode, $dob, $gender, $reg_fees, $paid_through, $refrence_number, $for_class, $last_school, $current_class, $username,$sibling_bool,$sibling)
{
    $sql_users = "UPDATE student_registration SET  name=?, fathername=?, mothername=?,mobile=?,email=?,address_line_1= ?,city=?,pincode=?,dob=?,gender=?,reg_fees = ?,paid_through = ?,refrence_number= ?,for_class=?,last_school=?,current_class=?,sibling_bool = ?,sibling = ? WHERE id=? and institution_id=?";
    $conn_rjllearning_specific->prepare($sql_users)->execute(array($name, $fathername, $mothername, $mobile, $email, $address_line_1, $city, $pincode, $dob, $gender, $reg_fees, $paid_through, $refrence_number, $for_class, $last_school, $current_class,$sibling_bool,$sibling,$reg_id, $institution_id));
    return true;
}


