load->model('User_Management_Model'); $this->load->library('AWS_S3'); $this->load->library('AWS_SES'); } public function listAllUsers_get() { //echo "function"; $entityid = null; $user_type = null; if($this->get('eid')){$entityid = $this->get('eid');} if($this->get('user_type')){$entityid = $this->get('user_type');} $result = $this->User_Management_Model->listAllUsers($entityid,$user_type); //echo "result"; if($result['data_status']) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result['data']; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $this->response($data,REST_Controller::HTTP_OK); } } public function saveNewUser_post() { $roles = ""; $lender_hierarchy = ""; $pdofficer = ""; $user_config = ""; if($this->post('roles')){ $roles = json_decode($this->post('roles'),true); } if($this->post('pdofficer')){ $pdofficer = json_decode($this->post('pdofficer'),true); } if($this->post('user_config')){ $user_config = json_decode($this->post('user_config'),true); } $records = json_decode($this->post('records'),true); if(!empty($_FILES['profilepic']['tmp_name'])) { $profilepic = $_FILES['profilepic']['tmp_name']; $profilepicname = $_FILES['profilepic']['name']; $profilepicname = strtolower($profilepicname); $profilepics3path = ""; if(array_key_exists('fk_entity_type_id',$records)) { $entity_id = $records['fk_entity_type_id']; if($entity_id == 1) //1 means sine_edge Profile { $profilepics3path = 'sineedge/'.$profilepicname; } else if($entity_id == 2)//1 means lender Profile { $profilepics3path = 'lender/'.$profilepicname; } else // else or 3 means vendor Profile { $profilepics3path = 'vendor/'.$profilepicname; } } $bucketname = PROFILE_PICTURE_BUCKET_NAME; $key = $profilepics3path; $sourcefile = $profilepic; $bucket_data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($bucket_data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $records['profilepic'] = $profilepicname; } else { $records['profilepic'] = null; } } // if(($records['fk_entity_id'] == 35 && ENVIRONMENT == 'testing') || ($records['fk_entity_id'] == 7 && ENVIRONMENT == 'prodcution')) // { // $records['user_type'] = 'SMC'; // } $user_id = $this->User_Management_Model->saveRecords($records,USERPROFILE);//insert user records and get userid if($roles != "") { // foreach($roles as $role) // { $role_array = array('user_role'=>$roles['user_role'],'fk_userid'=>$user_id);//insert roles againest user $this->User_Management_Model->saveRecords($role_array,USERPROFILEROLES); // } } // if($lender_hierarchy != "") // { // foreach($lender_hierarchy as $hierarchy) // { // $hierarchy = array('fk_hierarchy_id'=>$hierarchy['lender_hierarchy_id'],'fk_user_id'=>$user_id); // $this->User_Management_Model->saveRecords($hierarchy,USERPROFILEHIERARCHY); // } // } //print_r($pdofficer);die; if(array_key_exists('fk_entity_type_id',$records)) { $entity_id = $records['fk_entity_type_id']; $roles = $roles['user_role']; if($entity_id ==1 && ($roles == 5 || $roles ==4)){ if($roles == 5) { $pdofficer['fk_pd_type_id'] = 1; }else if($roles == 4) { $pdofficer['fk_pd_type_id'] = 2; } $pdofficer['fk_user_id'] = $user_id; //print_r($pdofficer); $this->User_Management_Model->saveRecords($pdofficer,PDOFFICIERSDETAILS); } } //save user configs if($user_config) { if(array_key_exists('salespd_products', $user_config)) { $salespd_products = (implode(',',$user_config['salespd_products'])); $arr = array('fk_user_id' => $user_id,'config_type' => 1,'data' => $salespd_products); $this->db->set($arr); $res = $this->db->insert(USERCONFIG); //print_r($res); } } if($user_id != '' || $user_id != null) { // send a verification mail for registered user to get PD alert informations // They have to clik a verification link from sent mail //$this->aws_ses->verifyEmailIdentity($records['email']); $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['record'] = $user_id; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $this->response($data,REST_Controller::HTTP_OK); } } public function updateExistUser_post() { $roles = ""; $lender_hierarchy = ""; $pdofficer = ""; $user_config = ""; if($this->post('pdofficer')){ $pdofficer = json_decode($this->post('pdofficer'),true);} if($this->post('lender_hierarchy')){ $lender_hierarchy = json_decode($this->post('lender_hierarchy'),true); } if($this->post('user_config')){ $user_config = json_decode($this->post('user_config'),true); } $records = json_decode($this->post('records'),true); // $records = array_filter($recordsData); $roles = json_decode($this->post('roles'),true); // $lender_hierarchy = json_decode($this->post('lender_hierarchy'),true); if(!empty($_FILES['profilepic']['tmp_name'])) { $profilepic = $_FILES['profilepic']['tmp_name']; $profilepicname = $_FILES['profilepic']['name']; $profilepicname = strtolower($profilepicname); $profilepics3path = ""; if(array_key_exists('fk_entity_type_id',$records)) { $entity_id = $records['fk_entity_type_id']; if($entity_id == 1) //1 means sine_edge Profile { $profilepics3path = 'sineedge/'.$profilepicname; } else if($entity_id == 2)//1 means lender Profile { $profilepics3path = 'lender/'.$profilepicname; } else // else or 3 means vendor Profile { $profilepics3path = 'vendor/'.$profilepicname; } } $bucketname = PROFILE_PICTURE_BUCKET_NAME; $key = $profilepics3path; $sourcefile = $profilepic; $data = array('bucket_name'=>$bucketname,'key'=>$key,'sourcefile'=>$sourcefile); $s3result= $this->aws_s3->uploadFileToS3Bucket($data); if(is_object($s3result) && $s3result['ObjectURL'] != '' && $s3result['@metadata']['statusCode'] == 200) { $records['profilepic'] = $profilepicname; } else { $records['profilepic'] = null; } } $where_condition_array = array('userid'=>$records['userid']); $modified = $this->User_Management_Model->updateRecords($records,USERPROFILE,$where_condition_array);//insert user records and get userid if($roles != "") { $this->User_Management_Model->updateRecords(array('isactive'=>0),USERPROFILEROLES,array('fk_userid'=>$records['userid'])); $role_array = array('user_role'=>$roles['user_role'],'fk_userid'=>$records['userid']); $this->User_Management_Model->saveRecords($role_array,USERPROFILEROLES); } // print_r($records); // print_r($roles);die; if(array_key_exists('fk_entity_type_id',$records)) { $entity_id = $records['fk_entity_type_id']; $roles = $roles['user_role']; if($entity_id ==1 && $roles == 5 || $roles ==4){ if($roles == 5) { $pdofficer['fk_pd_type_id'] = 1; }else if($roles == 4) { $pdofficer['fk_pd_type_id'] = 2; } //print_r($pdofficer);die; //print_r($pdofficer);die; $arr = array('fk_user_id'=>$pdofficer['fk_user_id']); $this->User_Management_Model->updateRecords($pdofficer,PDOFFICIERSDETAILS,$arr); } } //update user configs if($user_config) { if(array_key_exists('salespd_products', $user_config)) { $salespd_products = (implode(',',$user_config['salespd_products'])); $arr = array('fk_user_id' => $records['userid'],'config_type' => 1,'data' => $salespd_products); $this->db->set($arr); $this->db->where('fk_user_id', $records['userid']); $res = $this->db->update(USERCONFIG); //print_r($res); } } if($modified != '' || $modified != null || $modified != 0) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['record'] = $modified; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_MODIFIED; $this->response($data,REST_Controller::HTTP_OK); } } /** * sriram get roles function */ public function getUsersDetails_post(){ $userid = $this->post('userid'); $result = $this->User_Management_Model->getUserDetails($userid); $user_config = $this->User_Management_Model->getUserConfigDetails($userid); // print_r($result['data']);die(); $result['data'][0]['user_config'] = $user_config; if($result['data_status']) { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $result['data']; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $this->response($data,REST_Controller::HTTP_OK); } } /* Get Signed URL for profile picture @params userid , entity id, profilepic name URL expires 5 min */ public function getSingedProfilePicURL_post() { $userid = $this->post('userid'); $entityid = $this->post('entityid'); $profilepic = $this->post('profilepic'); $profilepics3path = ''; if($entityid == 1) //1 means sine_edge Profile { $profilepics3path = 'sineedge/'.$profilepic; } else if($entityid == 2)//1 means lender Profile { $profilepics3path = 'lender/'.$profilepic; } else // else or 3 means vendor Profile { $profilepics3path = 'vendor/'.$profilepic; } $singed_uri = $this->aws_s3->getSingleObjectInaBucketAsSignedURI(PROFILE_PICTURE_BUCKET_NAME, $profilepics3path,'+5 minutes'); if($singed_uri != null || $singed_uri != '') { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $singed_uri; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Profile URL Available'; $this->response($data,REST_Controller::HTTP_OK); } } /** * Check pin for mobile app * @params userid and pin * return data true or false; */ public function checkpin_post() { $records = $this->post('records'); $pin_details = $this->User_Management_Model->pinDetails($records); if($pin_details != null || $singed_uri != '') { $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['records'] = $pin_details['data']; $this->response($data,REST_Controller::HTTP_OK); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NO_CONTENT; $data['msg'] = 'No Profile URL Available'; $this->response($data,REST_Controller::HTTP_OK); } } /** USER CONFIGURATION SAVE AND UPDATE API * @PARAM post params sales_products, state mapping -- currently implemented for MWISE LENDER only */ public function saveOrUpdateUserConfig_post() { if($this->post('user_id')) { $user_id = $this->post('user_id'); $user_config = $this->User_Management_Model->getUserConfigDetails($user_id); // print_r($user_config); // die(); $salesproduct_msg = ""; $rcmstate_msg = ""; /** FOR SALES PD PRODUCTS ADD AND UPDATE */ if($this->post('salespd_products')){ $salespd_products = $this->post('salespd_products'); if($salespd_products && !empty($salespd_products)) { $salespd_products = (implode(',',$salespd_products)); $arr = array('fk_user_id' => $user_id,'config_type' => 1,'data' => $salespd_products); $this->db->set($arr); if(!$user_config || !array_key_exists('salespd_products',$user_config) || empty($user_config['salespd_products'])) { $res = $this->db->insert(USERCONFIG); $salesproduct_msg = "Sales Products Added"; } else{ $this->db->where('fk_user_id',$user_id); $res = $this->db->update(USERCONFIG); $salesproduct_msg = "Sales Products Updated"; } // print_r($res); } } /** END OF SALES PD PRODUCTS ADD AND UPDATE */ /** FOR INSERTING THE RCM STATE MAPPING DATA */ if($this->post('rcm_state_mapping')){ $rcm_state_mapping = $this->post('rcm_state_mapping'); } if($rcm_state_mapping && !empty($rcm_state_mapping)) { if(!$user_config || !array_key_exists('rcm_state_mapping',$user_config) || empty($user_config['rcm_state_mapping'])) { } else { $intersect_value = array_intersect($rcm_state_mapping,$user_config['rcm_state_mapping']); if(!empty($intersect_value)) { foreach( $intersect_value as $key => $value) { $key = (float) array_search($value,$rcm_state_mapping); unset($rcm_state_mapping[$key]); $key = (float) array_search($value,$user_config['rcm_state_mapping']); unset($user_config['rcm_state_mapping'][$key]); } if(!empty($user_config['rcm_state_mapping'])) { $this->User_Management_Model->deactivateDataOnRcmStateMapping($user_id,$user_config['rcm_state_mapping']); $rcmstate_msg = "RCM States Modified"; } } // print_r($rcm_state_mapping); // die(); // echo "\n old data \n"; // print_r($user_config['rcm_state_mapping']); // echo "new data"; // print_r($rcm_state_mapping); // die(); } if(!empty($rcm_state_mapping)) { $insert_value = array(); foreach($rcm_state_mapping as $key=>$value) { if($value) { array_push($insert_value,(object)[ "fk_user_id" => $user_id, "fk_state_id" => $value, "isactive" => "1" ]); } } if(!empty($insert_value)) { $res = $this->db->insert_batch(RCM_STATE_MAPPING,$insert_value); $rcmstate_msg = "RCM States Added"; } } } /** END OF INSERTING THE RCM STATE MAPPING DATA */ $response_msg = salesproduct_msg ? $salesproduct_msg : ''; $response_msg.= $response_msg && $rcmstate_msg ? ' and '.$rcmstate_msg : $rcmstate_msg ? ' '.$rcmstate_msg : ''; $data['dataStatus'] = true; $data['status'] = REST_Controller::HTTP_OK; $data['msg'] = $response_msg." Successully"; $this->response($data,REST_Controller::HTTP_OK); /** FOR GETTING SALES PRODUCTS */ // $user_id = $this->post('user_id'); // $user_config = $this->User_Management_Model->getUserConfigDetails($user_id); // print_r($user_config); } else { $data['dataStatus'] = false; $data['status'] = REST_Controller::HTTP_NOT_FOUND; $data['msg'] = 'User Not Found'; $this->response($data,REST_Controller::HTTP_NOT_FOUND); } } }