<?php
/// Includes helper code to get signup intent roles and signup reasons on registration form.

include_once("helper.php");   
class SecurityQuestion{
    
    public $question;
    public $sl_no;
    
    function populateQuestion( $row ){
        
        $this->question = $row["question"];
        $this->sl_no = $row["sl_no"];
        
    }
    
}

class SignUpRoles{
    
    public $name;
    public $role_id;
    
    function populateQuestion( $row ){
        
        $this->name = $row["name"];
        $this->role_id = $row["role_id"];
        
    }
    
}

class SignUpReasons{
    
    public $question;
    public $reason_id;
    
    function populateQuestion( $row ){
        
        $this->name = $row["name"];
        $this->reason_id = $row["reason_id"];
        
    }
    
}

// Getting Security Questions
// getSecurityQuestions();	
function getSecurityQuestions(){
    // print('before connt');
    $sql_conn = mysqli_connection();
    // print('after connt');
    $sql = sprintf("SELECT  * FROM  SecurityQuestions ORDER BY `sl_no`");
    
    $result = mysqli_query($sql_conn, $sql);

    $res = array();
    while($row = mysqli_fetch_array($result)) {
        $question = new SecurityQuestion();
        $question->populateQuestion($row);
        $res[] = $question;
    }
    
    mysqli_close($sql_conn);
    $r = json_encode($res);
    // print($r);
    return $r;
    
}

// getSignupRoles();
function getSignupRoles(){
    // print('before connt');
    $sql_conn = mysqli_connection();
    // print('after connt');
    $sql = sprintf("SELECT  * FROM  master_project_roles ORDER BY `role_id`");
    
    $result = mysqli_query($sql_conn, $sql);
    // print($result);
    $res = array();
    while($row = mysqli_fetch_array($result)) {
        $question = new SignUpRoles();
        $question->populateQuestion($row);
        $res[] = $question;
    }
    
    mysqli_close($sql_conn);
    $r = json_encode($res);
    // print($r);
    return $r;
    
}

function getSignupReasons(){
    // print('before connt');
    $sql_conn = mysqli_connection();
    // print('after connt');
    $sql = sprintf("SELECT  * FROM  signup_reasons ORDER BY `reason_id`");
    
    $result = mysqli_query($sql_conn, $sql);

    $res = array();
    while($row = mysqli_fetch_array($result)) {
        $question = new SignUpReasons();
        $question->populateQuestion($row);
        $res[] = $question;
    }
    
    mysqli_close($sql_conn);
    $r = json_encode($res);
    // print($r);
    return $r;
    
}

?>