<?php
$uID =intval($_POST['user_id']);

$u = $db->userInfoByID($uID);

if(empty($u)){$error=fl(); setMessage(36,'User');}
elseif($u['type']!=USER_TYPE_MANAGER&&$u['type']!=USER_TYPE_RSM){
    $error=fl(); setMessage(36,'User Type');
}
else{
    $q=[];  
    $q[]='group_id!='.SUPERADMIN_USER;
    if($u['type']==USER_TYPE_RSM){
        $q[]='type ='.USER_TYPE_MPO; 
    }
    elseif($u['type']==USER_TYPE_MANAGER){
        $q[]='type ='.USER_TYPE_RSM; 
    }

    $sq='where '.implode(' and ',$q);

    $users   = $db->selectAll('users',$sq,'',$general->showQuery());
    $assignd_users= $db->selectAll('user_manager','where assing_user_id='.$uID.' and isActive=1','assing_user_id,user_id',$general->showQuery());
    $all_assignd=[];
    foreach($assignd_users as $au){
          $all_assignd[]=$au['user_id'];
    }
    
    $gAr['users']   =$users;
    $gAr['assignd_users']   =$all_assignd;
    $jArray['html'] = $general->fileToVariable(__DIR__.'/user_assign_data.phtml');
    $jArray['status'] = 1;
    $jArray[fl()] = $u['type'];
}
?>
