<?php
//base path learning to resources

require_once '../base_path_include.php';
require_once $base_path_to_learning_resources . "/includes/connect.php";
$data = json_decode(file_get_contents('php://input'), true);

    try {

        $sql_users = "INSERT INTO users(name,dob,gender,username,email,mobile,institution_id,role,password,date_time_created,designation,status,can_activate)
                                   VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        $stmt_users =  $conn_rjllearning->prepare($sql_users);
          $rows = $data['user'];    
          $name = $rows['name'];
          $dob = $rows['dob'];
          $gender = $rows['gender'];
          $username = $rows['username'];
          $email = $rows['email'];
          $mobile = $rows['mobile'];
          $workspace_id = $rows['workspace_id'];
          $password = $rows['password'];
          $designation = $rows['designation'];
        //   $role = $rows['role'];
          
        if($rows['role'] == null){
            $role = 'subadmin'; 
        }else{
            $role = $rows['role'];
        }
          
          $excute_sql = $conn_rjllearning->prepare("SELECT * FROM users WHERE  institution_id = ? and (username= ? or email = ?) ");
          $excute_sql->execute(array($workspace_id, $username, $email));
          $result_users = $excute_sql->fetchAll();
          if (count($result_users) >= 1) {
            return false;
          }
          $stmt_users->execute(array($name, $dob, $gender, $username, $email, $mobile, $workspace_id, $role, $password, time(), $designation, '1','1'));
          
     
        return true;
    } catch (Exception $e) {
        echo "Error : " . $e->getMessage();
    }

